[Process] Hardcoding the command for shell
At the command line on most operating system, you can pipe a file into another program and then pipe out into a third program. For example: Take a file from the hard disk, decrypt it, and then unzip it: openssl rc4-40 -salt -d -pass pass:MyPassword < /home/frederick/monkey.tar.gz.encrypted > tar -zxf - I realise, when using Boost::Process, that we can tie the input and output streams of child processes together using 'ipstream', but I want to be able to take the above command and give it directly to the operating system (or to the 'shell'). On Linux x64 and armhf(32-Bit), the following works: child c(search_path("sh"), "-c", "openssl rc4-40 -salt -d -pass pass:MyPassword < /home/frederick/monkey.tar.gz.encrypted > tar -zxf -" ); But should I have to hardcode "sh" and "-c" into my program like that? I have tried using "shell" like this: child c( "openssl rc4-40 -salt -d -pass pass:MyPassword < /home/frederick/monkey.tar.gz.encrypted > tar -zxf -", shell ); but this doesn't work on either Linux x64 or armhf(32-Bit). I thought the whole point of "shell" was that you didn't have to hardcode "sh -c" in Linux or "cmd /c" in MS-Windows. Also if you do some web-searching for how to run a batch file in MS-Windows using boost::process, you'll see that everyone is doing this: context ctx; ctx.environment = self::get_environment(); child c = launch("cmd", "/c batch.bat", ctx); Should it be necessary to hardcode "cmd /c" like that? Shouldn't this all be taken care of by "boost::process::shell"? Frederick
https://en.cppreference.com/w/cpp/utility/program/system On Tue, 10 Mar 2020 at 08:22, Frederick Gotham via Boost-users < boost-users@lists.boost.org> wrote:
At the command line on most operating system, you can pipe a file into another program and then pipe out into a third program.
For example: Take a file from the hard disk, decrypt it, and then unzip it:
openssl rc4-40 -salt -d -pass pass:MyPassword < /home/frederick/monkey.tar.gz.encrypted > tar -zxf -
I realise, when using Boost::Process, that we can tie the input and output streams of child processes together using 'ipstream', but I want to be able to take the above command and give it directly to the operating system (or to the 'shell').
On Linux x64 and armhf(32-Bit), the following works:
child c(search_path("sh"), "-c", "openssl rc4-40 -salt -d -pass pass:MyPassword < /home/frederick/monkey.tar.gz.encrypted > tar -zxf -" );
But should I have to hardcode "sh" and "-c" into my program like that? I have tried using "shell" like this:
child c( "openssl rc4-40 -salt -d -pass pass:MyPassword < /home/frederick/monkey.tar.gz.encrypted > tar -zxf -", shell );
but this doesn't work on either Linux x64 or armhf(32-Bit). I thought the whole point of "shell" was that you didn't have to hardcode "sh -c" in Linux or "cmd /c" in MS-Windows.
Also if you do some web-searching for how to run a batch file in MS-Windows using boost::process, you'll see that everyone is doing this:
context ctx; ctx.environment = self::get_environment(); child c = launch("cmd", "/c batch.bat", ctx);
Should it be necessary to hardcode "cmd /c" like that? Shouldn't this all be taken care of by "boost::process::shell"?
Frederick _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org https://lists.boost.org/mailman/listinfo.cgi/boost-users
-- @systemdeg "We value your privacy, click here!" Sod off! - degski "Anyone who believes that exponential growth can go on forever in a finite world is either a madman or an economist" - Kenneth E. Boulding "Growth for the sake of growth is the ideology of the cancer cell" - Edward P. Abbey
On 3/11/20, degski
I cannot use std::system because I'm starting the second process with "boost::process::child" and then reading from the second process's stdout.
participants (2)
-
degski
-
Frederick Gotham