boost-process

How to reproduce deadlock hinted to by Boost process documentation?

会有一股神秘感。 提交于 2021-02-18 22:31:33
问题 According to the Boost documentation (section 'Why does the pipe not close?'), the following code will result in a deadlock: #include <boost/process.hpp> #include <iostream> namespace bp = ::boost::process; int main(void) { bp::ipstream is; bp::child c("ls", bp::std_out > is); std::string line; while (std::getline(is, line)) { std::cout << line << "\n"; } return 0; } The documentation says: This will also deadlock, because the pipe does not close when the subprocess exits. So the ipstream

cannot find boost_process cmake find_package

跟風遠走 提交于 2021-02-18 11:17:05
问题 I'm trying to import boost libraries into my C++ project, and for some reason it cannot find Boost.Process, although it finds the others. My CMakeLists.txt file: cmake_minimum_required(VERSION 3.9 FATAL_ERROR) set (PROJECT_NAME "test-stuff" CXX) project (${PROJECT_NAME}) set(Boost_USE_MULTITHREADED ON) find_package(Boost 1.64.0 REQUIRED system filesystem process) if(Boost_FOUND) include_directories (SYSTEM ${Boost_INCLUDE_DIR}) endif() include_directories(include) file(GLOB SOURCES "src/*.cpp

Boost::Process Pipe Streams and Unit Test

偶尔善良 提交于 2021-02-10 15:56:17
问题 I have source which two stream like this: bp::ipstream StdOut; bp::opstream StdIn; bp::child MyProcess = bp::child(processPath, bp::std_out > StdOut, bp::std_in < StdIn); // Doing some stuff with StdOut and StdIn I wanted to know if there is a way to write manually into this StdOut and read from StdIn in order to do unit tests? Thank you very much! 回答1: You can write to them as a normal stream: Live On Coliru #include <boost/process.hpp> #include <iostream> namespace bp = boost::process; int

boost::process system leaking file descriptors

夙愿已清 提交于 2021-02-10 03:10:13
问题 It seems like boost::process::system is leaking fds: Let's say I have this simple code to flush iptables config every 3 seconds (just an example): #include <boost/process.hpp> #include <thread> int main(void) { while(true) { std::this_thread::sleep_for(std::chrono::seconds(3)); boost::process::system(boost::process::search_path("iptables"), "-F"); } return 0; } If I observe the count of open file descriptors by listing /proc/PID/fd |wc -l , I can see that the count increases by one every 3

boost::process system leaking file descriptors

帅比萌擦擦* 提交于 2021-02-10 03:08:44
问题 It seems like boost::process::system is leaking fds: Let's say I have this simple code to flush iptables config every 3 seconds (just an example): #include <boost/process.hpp> #include <thread> int main(void) { while(true) { std::this_thread::sleep_for(std::chrono::seconds(3)); boost::process::system(boost::process::search_path("iptables"), "-F"); } return 0; } If I observe the count of open file descriptors by listing /proc/PID/fd |wc -l , I can see that the count increases by one every 3

boost::process system leaking file descriptors

一笑奈何 提交于 2021-02-10 03:07:58
问题 It seems like boost::process::system is leaking fds: Let's say I have this simple code to flush iptables config every 3 seconds (just an example): #include <boost/process.hpp> #include <thread> int main(void) { while(true) { std::this_thread::sleep_for(std::chrono::seconds(3)); boost::process::system(boost::process::search_path("iptables"), "-F"); } return 0; } If I observe the count of open file descriptors by listing /proc/PID/fd |wc -l , I can see that the count increases by one every 3

Boost::process child by id

只愿长相守 提交于 2021-01-29 04:59:42
问题 How I can get child.id() in on_exit function? bp::child c(args, ios, bp::on_exit([&](int e, std::error_code ec) { result = e; ios.stop(); //need c.id(); })); or how I can check in other function if the child is running by id? boost::process::child c(data->id); // doesn't work if (!c.running()) { } 回答1: You can bind whatever extra information you want to your handler. For example, you can declare your handler to take a reference to the child instance: static void exit_handler(bp::child&

Boost::process child by id

倾然丶 夕夏残阳落幕 提交于 2021-01-29 04:53:28
问题 How I can get child.id() in on_exit function? bp::child c(args, ios, bp::on_exit([&](int e, std::error_code ec) { result = e; ios.stop(); //need c.id(); })); or how I can check in other function if the child is running by id? boost::process::child c(data->id); // doesn't work if (!c.running()) { } 回答1: You can bind whatever extra information you want to your handler. For example, you can declare your handler to take a reference to the child instance: static void exit_handler(bp::child&

Close the stdin of boost::process child

六月ゝ 毕业季﹏ 提交于 2020-06-27 23:22:48
问题 I'm trying to call a process with a string to its stdin, with Boost-1.64.0. The current code is : bp::opstream inStream ; bp::ipstream outStream; bp::ipstream errStream; bp::child child( command, // the command line bp::shell, bp::std_out > outStream, bp::std_err > errStream, bp::std_in < inStream); // read the outStream/errStream in threads child.wait(); The problem is that the child executable is waiting for its stdin EOF. Here child.wait() is hanging indefinitely… I tried to used asio:

Close the stdin of boost::process child

怎甘沉沦 提交于 2020-06-27 23:22:30
问题 I'm trying to call a process with a string to its stdin, with Boost-1.64.0. The current code is : bp::opstream inStream ; bp::ipstream outStream; bp::ipstream errStream; bp::child child( command, // the command line bp::shell, bp::std_out > outStream, bp::std_err > errStream, bp::std_in < inStream); // read the outStream/errStream in threads child.wait(); The problem is that the child executable is waiting for its stdin EOF. Here child.wait() is hanging indefinitely… I tried to used asio: