本文介绍了在C升压过程库的输出++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用升压过程,并使用。

I use boost process and use a default code in main tutorials page.

我已经运行此code,并没有显示任何输出!

I have run this code and it didn't print any output!

#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; 
} 

任何一个可以帮我解决这个问题?

can any one help me with this problem?

这code出口这里。

谢谢!

推荐答案

您可能没有检查该进程是否成功启动。我可以简单地使用 /斌/ LS 而不是具有良好的成功:

You probably didn't check whether the process is successfully launched. I can simply use /bin/ls instead with good success:

// 
// 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失败 - 没有错误消息

Note that using "ls" fails - without an error message.

这篇关于在C升压过程库的输出++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 21:23