Boost logo

Boost :

Subject: Re: [boost] [gsoc] Boost.Process done
From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2010-10-29 14:30:26


Hello Boris,

To portably use boost::process::behavior::inherit, it should call in
it's constructor:

#if defined(BOOST_WINDOWS_API)
   if(h_.native())
   {
     if (!SetHandleInformation( h_.native()
                              , HANDLE_FLAG_INHERIT
                              , HANDLE_FLAG_INHERIT))
     BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR(
      "SetHandleInformation() failed");
   }
#endif

Otherwise the following use case fails on Windows to redirect output to
a file:

void inherit_test
(std::string exe, const args& a, std::string out, std::string err)
{
   boost::iostreams::file_descriptor_sink stdOutFile;
   boost::iostreams::file_descriptor_sink stdErrFile;
   boost::process::context ctx;

   if (!out.empty())
   {
     stdOutFile.open(out.c_str());
     ctx.streams[boost::process::stdout_id]
     = boost::process::behavior::inherit(stdOutFile.handle());
   }

   if (!standardErrorFile.empty())
   {
     stdErrFile.open(err.c_str());
     ctx.streams[boost::process::stderr_id]
     = boost::process::behavior::inherit(stdErrFile.handle());
   }

   boost::process::child c = boost::process::create_child(exe, a, ctx);

   c.wait();
}

Jeff


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk