I want to boost-process to start a process and write/read to its stdin/stdout. In principle the code works but it doesn't terminate. It seems to me that the external program does not receive a EOF, although I close the stream to write to the process' stdin. Any ideas how to make the process send a EOF? The code works if I remove the code to write to /bin/cat stdin. Then I can input the text and on Ctrl-D it terminates. Any ideas how to send a EOF over the stream?
My code:
std::vector<std::string> args;
args.push_back("/bin/cat");
boost::process::pipe procout = boost::process::create_pipe();
boost::process::pipe procin = boost::process::create_pipe();
{
boost::iostreams::file_descriptor_sink fdsink(procout.sink,
boost::iostreams::close_handle);
boost::iostreams::file_descriptor_source fdsource(procin.source,
boost::iostreams::close_handle);
boost::process::execute(
boost::process::initializers::set_args(args),
boost::process::initializers::bind_stdin(fdsource),
boost::process::initializers::bind_stdout(fdsink)
);
}
boost::iostreams::file_descriptor_source source(procout.source,
boost::iostreams::close_handle);
boost::iostreams::file_descriptor_sink sink(procin.sink,
boost::iostreams::close_handle);
boost::iostreams::stream<boost::iostreams::file_descriptor_source> is(source);
boost::iostreams::stream<boost::iostreams::file_descriptor_sink> os(sink);
os << "Some text " << std::endl;
os.close();
std::string s;
for (;;) {
std::getline(is, s);
if (is.eof()) {
break;
}
std::cout << s << std::endl;
}