3
我正忙着用boost进程库。但由于种种原因,我不能设法送东西给标准输入:写入子进程的stdin
#include <iostream>
#include <boost/process.hpp>
using namespace boost::process;
int main(int argc, char** argv) {
boost::asio::io_service ios;
std::future<std::string> outdata;
std::future<std::string> errdata;
child c("/usr/bin/cat",
std_out > outdata,
std_err > errdata,
std_in < "hi, there!", ios);
ios.run();
std::cout << "stdout: " << outdata.get() << std::endl;
std::cerr << "stderr: " << errdata.get() << std::endl;
}
我预计这个工作本质上就像
echo "hi, there" | cat
但是输出是空的。我错过了什么?
谢谢。它在API文档中,但我设法完全曲解它.... – choeger