mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
Add safety checks for process tools
This commit is contained in:
parent
227a302903
commit
3ca0d7236a
|
@ -15,6 +15,7 @@
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
namespace bp = boost::process;
|
||||||
|
|
||||||
namespace fair
|
namespace fair
|
||||||
{
|
{
|
||||||
|
@ -44,10 +45,17 @@ execute_result execute(const string& cmd, const string& prefix, const string& in
|
||||||
out << prefix << cmd << endl;
|
out << prefix << cmd << endl;
|
||||||
|
|
||||||
// Execute command and capture stdout, add prefix line by line
|
// Execute command and capture stdout, add prefix line by line
|
||||||
boost::process::ipstream c_stdout;
|
bp::ipstream c_stdout;
|
||||||
boost::process::opstream c_stdin;
|
bp::opstream c_stdin;
|
||||||
boost::process::child c(
|
bp::child c(cmd, bp::std_out > c_stdout, bp::std_in < c_stdin);
|
||||||
cmd, boost::process::std_out > c_stdout, boost::process::std_in < c_stdin);
|
|
||||||
|
while (c.valid() && !c.running()) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!c.valid()) {
|
||||||
|
throw runtime_error("Can't execute the given process.");
|
||||||
|
}
|
||||||
|
|
||||||
// Optionally, write to stdin of the child
|
// Optionally, write to stdin of the child
|
||||||
if (input != "") {
|
if (input != "") {
|
||||||
|
@ -57,8 +65,7 @@ execute_result execute(const string& cmd, const string& prefix, const string& in
|
||||||
}
|
}
|
||||||
|
|
||||||
string line;
|
string line;
|
||||||
while (getline(c_stdout, line))
|
while (c.running() && getline(c_stdout, line)) {
|
||||||
{
|
|
||||||
// print full line thread-safe
|
// print full line thread-safe
|
||||||
stringstream printLine;
|
stringstream printLine;
|
||||||
printLine << prefix << line << "\n";
|
printLine << prefix << line << "\n";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user