Boost logo

Boost Users :

From: Frederick Gotham (cauldwell.thomas_at_[hidden])
Date: 2020-03-10 08:38:47


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 list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net