boost-process

Declaring a variable of user-defined type for later initialization

旧巷老猫 提交于 2019-12-13 22:03:23
问题 I want to create a global variable called process without assigning anything to it in a first moment. Later on I'll spawn a new process in the operating system, and assign it to that variable. It can be done in C# like so: class TestCS { // creating a variable private System.Diagnostics.Process process; private void SomeMethod() { // assigning a newly spawned process to it process = Process.Start("file.exe", "-argument"); process.WaitForInputIdle(); } } I wrote the code below to accomplish

Race condition in starting up sub processes causes reading from pipe to hang

南楼画角 提交于 2019-12-12 02:12:13
问题 I have two threads that start up a child process each. The first application is a binary that runs quite long. The second exits quite quickly. There is a race condition that sometimes causes this to fail. Below I have a minimum viable code example. It uses Boost Process 0.5, which uses the standard fork / execve / dup2 system. There are some hacks regarding how Boost Process works, but in general it works quite well. The parent process starts up a lot more processes, and in general it works.

Get stdout of a shell command using boost process

有些话、适合烂在心里 提交于 2019-12-10 21:58:29
问题 I am trying to implement a function in C++ that runs a shell command and returns the exit code, stdout and stderr. I am using the Boost process library std::vector<std::string> read_outline(std::string & file) { bp::ipstream is; //reading pipe-stream bp::child c(bp::search_path("nm"), file, bp::std_out > is); std::vector<std::string> data; std::string line; while (c.running() && std::getline(is, line) && !line.empty()) data.push_back(line); c.wait(); return data; } In the above example from

How to retrieve program output as soon as it printed?

孤街浪徒 提交于 2019-12-06 12:01:11
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? 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 one two three four; do sleep "$(($RANDOM%2)).$(($RANDOM%10))"; echo "line $a"; done)--" }; bp::ipstream output

simultaneous read and write to child's stdio using boost.process

Deadly 提交于 2019-12-02 13:43:04
问题 i am trying to write and read to child's stdio using boost.process using something like this: boost::asio::io_service writeService, readService; bp::async_pipe in{writeService}; bp::async_pipe out{readService}; bp::child process(CompressCmd.c_str(), bp::std_in < in, bp::std_out > out); Buffer src; src.reserve(4 * 1024 * 1024); integer_type read = 0; //std::atomic_int64_t totalWrite{0}; integer_type totalWrite = 0; while (callback(CallbackActions::NeedMoreInput, src, read)) { in.async_write

Read child process stdout in a separate thread with BOOST process

限于喜欢 提交于 2019-12-02 07:38:49
问题 I have a main program that uses boost process library to spawn a child process that prints Hello World ! on its stdout every 5 seconds. I would like to read/monitor the stdout of the child process in the main process when it becomes available along with performing other operations within the main program. I have tried out the examples for boost asynchronous IO (http://www.boost.org/doc/libs/1_66_0/doc/html/boost_process/tutorial.html) but all these seem to block the main program until the

simultaneous read and write to child's stdio using boost.process

不想你离开。 提交于 2019-12-02 06:58:17
i am trying to write and read to child's stdio using boost.process using something like this: boost::asio::io_service writeService, readService; bp::async_pipe in{writeService}; bp::async_pipe out{readService}; bp::child process(CompressCmd.c_str(), bp::std_in < in, bp::std_out > out); Buffer src; src.reserve(4 * 1024 * 1024); integer_type read = 0; //std::atomic_int64_t totalWrite{0}; integer_type totalWrite = 0; while (callback(CallbackActions::NeedMoreInput, src, read)) { in.async_write_some( boost::asio::buffer(src.data(), read), [](const boost::system::error_code &e, std::size_t) { }); //

Read child process stdout in a separate thread with BOOST process

落花浮王杯 提交于 2019-12-02 04:55:32
I have a main program that uses boost process library to spawn a child process that prints Hello World ! on its stdout every 5 seconds. I would like to read/monitor the stdout of the child process in the main process when it becomes available along with performing other operations within the main program. I have tried out the examples for boost asynchronous IO ( http://www.boost.org/doc/libs/1_66_0/doc/html/boost_process/tutorial.html ) but all these seem to block the main program until the child process has exited. Do we need to read the childs stdout in a separate thread ? Can someone please

Boost::process output blank lines

ⅰ亾dé卋堺 提交于 2019-11-28 10:23:27
问题 I am developing an application where I need to launch and stop a variety of different executables depending on user input. I would like my "core" program to run as normal whilst these executables run, i.e not wait for their termination which could theoretically be infinte. As well as this I need to be able to receive std_out and send std_in to these executables. At the moment I have a set up where I have a process manager class: class ProcessManager { private: std::vector<patchProcess>

Where is Boost.Process?

若如初见. 提交于 2019-11-26 04:19:29
问题 I need to execute a program and retrieve its stdout output in c++. I\'d like my code to be cross-platform too. Having recently discovered the wonderful world of the Boost c++ libraries for all your cross platform needs, I figured I\'d just go to boost.org and read up on the documentation of Boost.Process. Much to my surprise, it wasn\'t there! I then proceeded to figure out what name Boost gave their cross-platform library to start external processes, but haven\'t managed to find it so far. A