[Saga-devel] saga SVN commit 3367:
/trunk/saga/saga/adaptors/utils/process/
amerzky at cct.lsu.edu
amerzky at cct.lsu.edu
Fri Jan 23 21:07:48 CST 2009
User: amerzky
Date: 2009/01/23 09:07 PM
Modified:
/trunk/saga/saga/adaptors/utils/process/
process.cpp, process.hpp
Log:
allow for non-io boost processes (sometimes, getline simply
hangs forever even if the process is already dead)
A
File Changes:
Directory: /trunk/saga/saga/adaptors/utils/process/
===================================================
File [modified]: process.cpp
Delta lines: +18 -10
===================================================================
--- trunk/saga/saga/adaptors/utils/process/process.cpp 2009-01-24 02:44:16 UTC (rev 3366)
+++ trunk/saga/saga/adaptors/utils/process/process.cpp 2009-01-24 03:07:36 UTC (rev 3367)
@@ -137,7 +137,7 @@
// run a process, and return stdout. In case of errors, throw a NoSuccess with
// stderr as error message
//
- std::vector <std::string> process::run_sync (void)
+ std::vector <std::string> process::run_sync (bool io)
{
try
{
@@ -145,6 +145,9 @@
fail_ = false;
done_ = false;
+ clear_out ();
+ clear_err ();
+
if ( cmd_ == "")
{
std::cout << " === no cmd\n";
@@ -170,9 +173,12 @@
boost::process::launcher l;
- l.set_stdin_behavior (boost::process::redirect_stream);
- l.set_stdout_behavior (boost::process::redirect_stream);
- l.set_stderr_behavior (boost::process::redirect_stream);
+ if ( io )
+ {
+ l.set_stdin_behavior (boost::process::redirect_stream);
+ l.set_stdout_behavior (boost::process::redirect_stream);
+ l.set_stderr_behavior (boost::process::redirect_stream);
+ }
std::map <std::string, std::string> :: iterator it;
@@ -183,14 +189,16 @@
c_ = l.start (cl);
- boost::process::postream & in = c_.get_stdin ();
- boost::process::pistream & out = c_.get_stdout ();
- boost::process::pistream & err = c_.get_stderr ();
+ if ( io )
+ {
+ boost::process::postream & in = c_.get_stdin ();
+ boost::process::pistream & out = c_.get_stdout ();
+ boost::process::pistream & err = c_.get_stderr ();
+ for ( std::string line; out.good () && getline (out, line); out_v_.push_back (line) );
+ for ( std::string line; err.good () && getline (err, line); err_v_.push_back (line) );
+ }
- for ( std::string line; getline (out, line); out_v_.push_back (line) );
- for ( std::string line; getline (err, line); err_v_.push_back (line) );
-
boost::process::status status = c_.wait();
if ( ! status.exited () || status.exit_status () )
File [modified]: process.hpp
Delta lines: +1 -1
===================================================================
--- trunk/saga/saga/adaptors/utils/process/process.hpp 2009-01-24 02:44:16 UTC (rev 3366)
+++ trunk/saga/saga/adaptors/utils/process/process.hpp 2009-01-24 03:07:36 UTC (rev 3367)
@@ -70,7 +70,7 @@
void set_env (std::map <std::string, std::string> env);
void add_env (std::string key, std::string val);
- std::vector <std::string> run_sync (void);
+ std::vector <std::string> run_sync (bool io = true);
void clear_out (void);
void clear_err (void);
More information about the saga-devel
mailing list