boost::process child terminates before all of stdout can be read

768 Views Asked by At

I want to use boost-process to read the stdout from a command:

std::string command = "cat /tmp/my_file";

namespace bp = boost::process;
bp::ipstream is;
bp::child c(command, bp::std_out > is);

std::string line;

int no_lines = 0;
while (c.running() && std::getline(is, line) && !line.empty()) {
    ++no_lines;
}
c.wait();

std::cout << "line count: " << no_lines << "\n";

This is almost identical to the boost-process tutorial.

For testing, the "command" is simply dumping a text file containing 10000 lines.

The problem is my code doesn't read in all the output from the command (for the test case, it only reads in about 9700 lines).

What am I doing wrong?

It seems like the child process is terminating before all of the stdout has been read.

0

There are 0 best solutions below