boost::process::on_exit示例程序
在使用boost::process库时,经常需要通过on_exit函数来设置进程结束后的回调处理方法。以下是一个简单的示例程序,演示如何使用on_exit函数:
#include <iostream>
#include <boost/process.hpp>
using namespace boost::process;
void onExitHandler(child c, const boost::system::error_code& ec) {
std::cout << "process exited with code " << c.exit_code() << std::endl;
}
int main() {
std::string command = "echo Hello world!";
ipstream out;
child c(command, std_out > out);
async_on_exit(c, onExitHandler);
c.wait();
std::cout << "captured output: " << out.rdbuf() << std::endl;
return 0;
}
在这个示例程序中,我们使用child类启动一个