Unable to capture standard output of process using Boost.Process Unable to capture standard output of process using Boost.Process windows windows

Unable to capture standard output of process using Boost.Process


Well I think that you need to redirect correctly the output stream. In my application something like this works :

[...]bp::command_line cl(_commandLine);bp::launcher l;l.set_stdout_behavior(bp::redirect_stream);l.set_stdin_behavior(bp::redirect_stream);l.set_merge_out_err(true);bp::child c = l.start(cl);bp::pistream& is = c.get_stdout();string result;string line;while (std::getline(is, line) && !_isStopped){    result += line;}c.wait();[...]

Without the redirect the stdout will go nowhere if I remember correctly. It is a good practice to wait for the process end if you want to get the whole output.

EDIT:

I'm on Linux with perhaps an old version of boost.process. i realize that your code is similar to the snippet I gave you. The c.wait() might be the key ...

EDIT: Boost.process 0.1 :-)


If migrating to the "latest" boost.process isn't an issue (as you sure know, there are several variants for this library) ,you could use the following (http://www.highscore.de/boost/process0.5/)

file_descriptor_sink sink("stdout.txt");execute(    run_exe("test.exe"),    bind_stdout(sink));