我使用升压过程并使用默认代码主要教程页面 http://www.highscore.de/boost/process/process/tutorials.html.
我已经运行了这段代码,但它没有打印任何输出!
#include <boost/process.hpp>
#include <string>
#include <vector>
#include <iostream>
namespace bp = ::boost::process;
int main()
{
std::string exec = "bjam";
std::vector<std::string> args;
args.push_back("--version");
bp::context ctx;
ctx.stdout_behavior = bp::capture_stream();
bp::child c = launch(exec, args, ctx);
bp::pistream &is = c.get_stdout();
std::string line;
while (std::getline(is, line))
std::cout << line << std::endl;
}
任何人都可以帮我解决这个问题吗?
这段代码退出here http://www.highscore.de/boost/process/process/tutorials.html#process.tutorials.read_from_child.
Thanks!
您可能没有检查进程是否成功启动。我可以简单地使用/bin/ls
相反,取得了良好的成功:
//
// Boost.Process
// ~~~~~~~~~~~~~
//
// Copyright (c) 2006, 2007 Julio M. Merino Vidal
// Copyright (c) 2008 Boris Schaeling
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/process.hpp>
#include <string>
#include <vector>
#include <iostream>
namespace bp = ::boost::process;
bp::child start_child()
{
std::string exec = "/bin/ls";
std::vector<std::string> args;
args.push_back("-ltrah");
bp::context ctx;
ctx.stdout_behavior = bp::capture_stream();
return bp::launch(exec, args, ctx);
}
int main()
{
bp::child c = start_child();
bp::pistream &is = c.get_stdout();
std::string line;
while (std::getline(is, line))
std::cout << line << std::endl;
}
请注意,使用"ls"
失败 - 没有错误消息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)