Reputation: 521
I would like to store the child of boost::process, but do not know how to initialize it
OS : win7 64 bits compiler : msvc2008 32bits boost : 1_55_0
example after simplify
#include <boost/process/initializers.hpp>
#include <boost/process.hpp>
#include <boost/system/system_error.hpp>
#include <iostream>
void test_boost_system()
{
namespace bp = boost::process;
namespace bpi = boost::process::initializers;
//bp::child child; //#1
boost::system::error_code ec;
bp::child child_2 = bp::execute(bpi::run_exe("ldapInterface.exe"), bpi::set_on_error(ec));
if(ec.value() != 0){
std::cout<<ec.message()<<std::endl;
}else{
std::cout<<"success"<<std::endl;
}
}
How could I initialize the child if I do not want to use the execute to initialize it in place?
pseudo codes :
namespace bp = boost::process;
namespace bpi = boost::process::initializers;
class process_manager
{
public:
~process_manager() { bp::terminate(child_); }
void open_process(std::string const &process)
{
child_ = bp::execute(bpi::run_exe(process)); //compile error
}
private:
bp::child child_;
};
error message : error C2512: 'boost::process::windows::child' : no appropriate default constructor available
Upvotes: 4
Views: 1600
Reputation: 393487
Use a wrapper that allows you to lazily initialize.
E.g.
class process_manager
{
public:
~process_manager() { if (child_) bp::terminate(*child_); }
void open_process(std::string const &process)
{
child_ = bp::execute(bpi::run_exe(process)); //compile error
}
private:
boost::optional<bp::child> child_;
};
Upvotes: 5