76 std::vector<std::string> args,
80 my->pctx.work_dir = work_dir.
string();
84 my->pctx.streams[boost::process::stdout_id] = bp::behavior::async_pipe();
86 my->pctx.streams[boost::process::stdout_id] = bp::behavior::null();
90 my->pctx.streams[boost::process::stderr_id] = bp::behavior::async_pipe();
92 my->pctx.streams[boost::process::stderr_id] = bp::behavior::null();
95 my->pctx.streams[boost::process::stdin_id] = bp::behavior::async_pipe();
97 my->pctx.streams[boost::process::stdin_id] = bp::behavior::close();
106 my->child.reset(
new bp::child( bp::create_child( exe.
string(), fc::move(args), my->pctx ) ) );
109 bp::handle outh = my->child->get_handle( bp::stdout_id );
110 my->_outp.reset(
new bp::pipe( fc::asio::default_io_service(), outh.release() ) );
113 bp::handle errh = my->child->get_handle( bp::stderr_id );
114 my->_errp.reset(
new bp::pipe( fc::asio::default_io_service(), errh.release() ) );
117 bp::handle inh = my->child->get_handle( bp::stdin_id );
118 my->_inp.reset(
new bp::pipe( fc::asio::default_io_service(), inh.release() ) );
122 promise<int>::ptr
p(
new promise<int>(
"process"));
123 my->stat.async_wait( my->child->get_id(), [=](
const boost::system::error_code& ec,
int exit_code )
127 #ifdef BOOST_POSIX_API
128 if( WIFEXITED(exit_code) ) p->set_value( WEXITSTATUS(exit_code) );
132 fc::exception_ptr( new fc::exception(
133 FC_LOG_MESSAGE( error,
"process exited with: ${message} ",
134 (
"message", strsignal(WTERMSIG(exit_code))) ) ) ) );
137 p->set_value(exit_code);
143 fc::exception_ptr( new fc::exception(
144 FC_LOG_MESSAGE( error,
"process exited with: ${message} ",
145 (
"message", boost::system::system_error(ec).what())) ) ) );
148 if( opt & open_stdin )
149 my->_in = std::make_shared<buffered_ostream>(std::make_shared<fc::asio::ostream<bp::pipe>>(my->_inp));
150 if( opt & open_stdout )
151 my->_out = std::make_shared<buffered_istream>(std::make_shared<fc::asio::istream<bp::pipe>>(my->_outp));
152 if( opt & open_stderr )
153 my->_err = std::make_shared<buffered_istream>(std::make_shared<fc::asio::istream<bp::pipe>>(my->_errp));