2

PHP には という便利な関数がありますproc_openstdin実行可能ファイルを呼び出し、そのを開き、パイプとして使用できstdoutますstderr

C++ でこの関数の優れたクロスプラットフォーム バージョンはありますか? グーグルで検索できるのは、Windows 用のこのチュートリアルだけです (ただし、このチュートリアルのコードはハングするだけです)。

4

2 に答える 2

3

あなたはおそらく「どこか」を得ることができます

于 2013-09-11T19:33:35.253 に答える
1

編集:

私が見ることができるように、Boost.Process はもはやアクティブな開発ではなく、例は現在の (1.54) およびそれほど最新ではない (1.4x - ブーストをアップグレードする前に正確なバージョンを書き留めるのを忘れた) バージョンでコンパイルされていません。のブーストなので、推奨事項を撤回する必要があります。

元の投稿

使用できるBoost.Processライブラリがあります。ここで良い例を見つけることができます。また、この章だけでなく、ここからこのを確認してください。

// 
// 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 = "bjam"; 

    std::vector<std::string> args; 
    args.push_back("--version"); 

    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; 
} 
于 2013-09-11T19:34:35.890 に答える