arun11299 / cpp-subprocess

Subprocessing with modern C++
Other
456 stars 90 forks source link

Popen fails to return error code in shell mode #37

Open klosworks opened 5 years ago

klosworks commented 5 years ago

I would expect this code:

    using namespace subprocess;
    auto proc = Popen("ls fdklajfdlsajfdkljaf", error{PIPE}, cwd{where}, shell{true});
    auto errors = proc.communicate().first;
    std::cerr << errors.buf.data() << std::endl;
    int exit_code = proc.wait();
    if(exit_code != 0)
    {
        cerr << "the command " << command << " returned error code " << exit_code << endl;
        exit(1);
    }

to set the exit_code variable to 2 and exit. Instead it sets it to 0 and goes on.