[英]C++ proc_open analogue
您可能會與“某處”
popen
( http://linux.die.net/man/3/popen )
pstreams庫 (POSIX流程控制)-我對此沒有任何經驗,但是看起來很扎實,由喬納森·韋克利(Jonathan Wakely)編寫
增強處理( http://www.highscore.de/boost/process/ ,尚未增強)
Poco :: Process launch
( http://www.appinf.com/docs/poco/Poco.Process.html#13423 )
static ProcessHandle launch( const std::string & command, const Args & args, Pipe * inPipe, Pipe * outPipe, Pipe * errPipe );
編輯:
如我所見,Boost.Process不再處於活動開發中,並且示例未使用當前版本(1.54)進行編譯,也不是當前版本(1.4x-在升級Boost之前我記下了確切的版本)版本的提升,所以我需要撤消我的建議。
原始帖子
有可以使用的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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.