#include #include #include #include #include namespace bp = boost::process; namespace bpb = boost::process::behavior; int main() { std::string exe = "/home/boost/boost_1_43_0/bin.v2/libs/process/test/gcc-4.2.1/debug/helpers"; std::vector args; args.push_back("echo-stdout-stderr"); args.push_back("message-to-two-streams"); bp::context ctx; // File descriptors must be closed after context is instantiated as the // context constructor uses the behavior inherit which tries to dup() // stdin, stdout and stderr. for (int i = 0; i < 100; ++i) close(i); ctx.stdout_behavior = bpb::pipe::create(bpb::pipe::output_stream); ctx.stderr_behavior = bpb::pipe::create(bpb::pipe::output_stream); bp::child c = bp::create_child(exe, args, ctx); std::string out, err, word1, word2; bp::pistream &isout = c.get_stdout(); isout >> out >> word1; // stdout message-to-two-streams bp::pistream &iserr = c.get_stderr(); iserr >> err >> word2; // stderr message-to-two-streams c.wait(); if (out == err) return EXIT_FAILURE; if (word1 != word2) return EXIT_FAILURE; if (isout.handle().native() == iserr.handle().native()) return EXIT_FAILURE; }