boost-process

Running a process using boost process in async mode with timeout

余生颓废 提交于 2020-06-27 16:35:31
问题 In the following code, I am trying to implement a program that runs a shell command and get the stdio , stderr and return code. I am doing it using boost process in the async mode as advised here. namespace bp = boost::process; class Process { public: Process(std::string & cmd, const int timeout); void run(); private: void timeout_handler(); const std::string command; const int timeout; bool killed; bool stopped; std::string stdOut; std::string stdErr; int returnStatus; boost::asio::io

Can't get segmentation fault exit code from boost child process

一世执手 提交于 2020-01-13 05:45:24
问题 I am trying to get the exit code of a child process (using boost::process and boost::asio) when that child process is killed due to a segmentation violation or divide be zero or any other kill signal. The exit code and error code always return with 0 and success. I am running this on CentOS 7 using g++ 4.8.5 and boost 1.66 If I run the same code with a child process that simply returns a non-zero exit code it successfully returns that exit code. #include <iostream> #include <boost/process.hpp

boost process running() and exit_code() thread safety

ぐ巨炮叔叔 提交于 2020-01-05 08:55:11
问题 I am using boost::process::child and boost::process::async_pipe to start an application and read asynchronously (through the means of boost::asio ) everything that app outputs on screen whenever this happens. I want to check also if the application is alive by using child::running() method; if not running I'd like to read the exit code using child::exit_code . This is very useful ESPECIALLY as it is a way to be notified about an application crashing or exiting unexpectedly (I could not find a

boost::process async IO example doesn't work?

爷,独闯天下 提交于 2020-01-05 06:50:52
问题 The following program: #include <boost/asio.hpp> #include <boost/process.hpp> #include <iostream> namespace bp = boost::process; int main() { boost::asio::io_service ios; std::vector<char> buf(4096); bp::async_pipe ap(ios); bp::child c("/bin/ls", bp::std_out > ap); boost::asio::async_read(ap, boost::asio::buffer(buf), [](const boost::system::error_code &ec, std::size_t size){}); ios.run(); int result = c.exit_code(); std::cout << result << std::endl; } outputs 383 . I would expect it to

Why does _popen work here, but boost::process does not?

浪子不回头ぞ 提交于 2020-01-04 13:29:39
问题 I have the following working code using _popen, on windows, m_pGNUPlot = _popen("/gnuplot/bin/gnuplot.exe", "w"); fprintf(m_pGNUPlot, "set term win\n"); fprintf(m_pGNUPlot, "set term pngcairo\n"); fprintf(m_pGNUPlot, "plot \"\Data.txt\" using 1:2 notitle\n"); fprintf(m_pGNUPlot, "set output \"\Out.png\"\n"); fprintf(m_pGNUPlot, "replot\n"); fflush(m_pGNUPlot); But the problem with this is that cmd window keeps poping up, and there is no way to prevent that (Link) So, I write the equivalent

Why does _popen work here, but boost::process does not?

筅森魡賤 提交于 2020-01-04 13:26:24
问题 I have the following working code using _popen, on windows, m_pGNUPlot = _popen("/gnuplot/bin/gnuplot.exe", "w"); fprintf(m_pGNUPlot, "set term win\n"); fprintf(m_pGNUPlot, "set term pngcairo\n"); fprintf(m_pGNUPlot, "plot \"\Data.txt\" using 1:2 notitle\n"); fprintf(m_pGNUPlot, "set output \"\Out.png\"\n"); fprintf(m_pGNUPlot, "replot\n"); fflush(m_pGNUPlot); But the problem with this is that cmd window keeps poping up, and there is no way to prevent that (Link) So, I write the equivalent

Blocking signals causes boost process not to work

你离开我真会死。 提交于 2019-12-25 03:51:42
问题 In the code below the class Process can run a process using boost process in asynchronous mode and can kill it if it times out. Now in order to shut it down, I block all the signals in all threads and create a specific thread signal_thread to handle signals. On doing this the program stops working. I guess this is probably because the parent process can no longer receive the signal SIGCHLD and know that the child process has finished executing. #include <iostream> #include <csignal> #include

How to retrieve program output as soon as it printed?

柔情痞子 提交于 2019-12-22 17:58:08
问题 I have a boost::process::child. There are many examples on how to get all its stdout or stderr in a single vector, but in this method you capture all data at once. But how to retrieve lines/characters as soon as they are printed in child process? 回答1: The docs are here: Synchronous IO Asynchronous IO Using ipstream The simplest way: Live On Coliru #include <boost/process.hpp> #include <iostream> namespace bp = boost::process; int main() { std::vector<std::string> args { "-c", R"--(for a in

How to retrieve program output as soon as it printed?

前提是你 提交于 2019-12-22 17:57:52
问题 I have a boost::process::child. There are many examples on how to get all its stdout or stderr in a single vector, but in this method you capture all data at once. But how to retrieve lines/characters as soon as they are printed in child process? 回答1: The docs are here: Synchronous IO Asynchronous IO Using ipstream The simplest way: Live On Coliru #include <boost/process.hpp> #include <iostream> namespace bp = boost::process; int main() { std::vector<std::string> args { "-c", R"--(for a in

How to ensure that we read all lines from boost::child process

和自甴很熟 提交于 2019-12-21 04:17:07
问题 I saw the following code on boost::child documentation page where they explain how to read the output of a child process. http://www.boost.org/doc/libs/1_64_0/doc/html/boost_process/tutorial.html They say after running your child process, we can read it via this loop:- bp::ipstream is; //reading pipe-stream bp::child c(bp::search_patk("nm"), file, bp::std_out > is); //then later while (c.running() && std::getline(is, line) && !line.empty()) data.push_back(line); I have 2 questions here :- If