C++(boost):通过boost::process::child同步调用其他程序

编程入门 行业动态 更新时间:2024-10-18 22:35:59

C++(boost):通过boost::process::child同步调用其他<a href=https://www.elefans.com/category/jswz/34/1771429.html style=程序"/>

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同步调用其他程序

本文发布于:2023-12-07 13:36:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1671333.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   boost   process   child

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!