I try to use boost::process
, it looks like very buggy part of boost; anyway, may be anyone knows workaround.
The most common task is to execute process and get its full (really full) output. Also generally output may be binary one and hence we can not use string
in generic case.
Asynchronous example from boost
documentation doesn't work, other articles on this forum mention that already, so I tried to use the most simple synchronous algorithm. Of course, I know about deadlocks risk, but boost
doesn't come to this point, it fails before.
The code idea follows:
bool ReadPipe(boost::process::ipstream &pipe, vector<char> &output)
{
char buffer[4096];
pipe.read(buffer, 4096);
auto bytesRead = pipe.gcount();
if (bytesRead)
output.insert(output.end(), buffer, buffer + bytesRead);
return bytesRead != 0;
}
boost::process::ipstream output;
vector<char> processOutput;
string cmdline = "somthing";
boost::process::child c(cmdLine.c_str(),
boost::process::std_in.close(),
boost::process::std_out > output);
while (c.running())
Reader::ReadPipe(output, processOutput);
Reader::ReadPipe(output, processOutput);
In this code we create process, redirect its standard output to ipstream
, read it while application runs, and read possible rest of data after application existed.
On Windows it works OK. On Ubuntu 16 it sometimes works, sometimes returns partial output and sometimes returns no output.
Does anyone have idea why it is so unstable, and is there any realistic way to use boost::process
to get full, possibly binary output from any application, just like Linux terminal can do it?