管道是经常使用的,比如:
$ cat file.txt
this is data 1
this is date 1
this is data 2
this is date 2
$ cat file.txt | grep data
this is data 1
this is data 2
那么通过C++怎么实现这种管道调用呢,实际上boost有提供方法:
#include <boost/process.hpp>
#include <iostream>
#include <string>
inline std::tuple<int, std::string, std::vector<std::string>>
execCmdWithPipe(std::string bin1Path, std::vector<std::string> bin1Args,
std::string bin2Path, std::vector<std::string> bin2Args)
{
namespace bp = boost::process;
std::string cmdStr = bin1Path;
for (const auto& arg : bin1Args)
{
cm