程序"/>
C++(boost):通过boost::process::child同步调用其他程序
boost提供了boost::process::child,可以通过其调用其他程序,并获得输出:
#include <boost/process/child.hpp>
#include <boost/process/io.hpp>
#include <vector>
#include <iostream>
#include <string>
#include <tuple>using namespace std;template <typename... ArgTypes>
tuple<int, vector<string> > execCmd(const char* path, ArgTypes&&... tArgs)
{vector<string> stdOutput;boost::process::ipstream stdOutStream;boost::process::child execProg(path, const_cast<char*>(tArgs)...,boost::process::std_out > stdOutStream);string stdOutLine;while (stdOutStream && getline(stdOutStream, stdOutLine) && !stdOutLine.empty()){stdOutput.emplace_back(stdOutLine);}execProg.wait();int retCode = execProg.exit_code();return make_tuple(retCode, stdOutput);
}int main()
{int cmdRetC
更多推荐
C++(boost):通过boost::process::child同步调用其他程序
发布评论