2013-04-21 2 views
3

Я использую процесс boost и использую код по умолчанию в main tutorials page.выход с библиотекой ускорения процесса в C++

Я запустил этот код и не распечатывал какой-либо выход!

#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.

Спасибо!

ответ

1

Возможно, вы не смогли проверить, успешно ли запущен процесс. Я могу просто использовать /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" терпит неудачу - без сообщения об ошибке.

Смежные вопросы