代碼:
#include <boost/system/process.hpp>
int main() {
boost::process::system bp("echo foo; echo bar");
}
輸出:
foo;回聲條
期望的輸出:
foo
bar
我收到一個字串,其中包含要運行的 1:MANY 命令,以分號分隔;因為可能會在 shell 終端中運行。有沒有辦法告訴 boost::process 像這樣解釋字串命令?
uj5u.com熱心網友回復:
是的,我會使用明確的 bash:
住在科利魯
#include <boost/process.hpp>
namespace bp = boost::process;
int main() {
bp::child c(
bp::search_path("bash"),
std::vector<std::string>{
"-c", "echo foo; for a in {1..10}; do echo \"bar $a\"; done"});
c.wait();
}
印刷
foo
bar 1
bar 2
bar 3
bar 4
bar 5
bar 6
bar 7
bar 8
bar 9
bar 10
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/460429.html
下一篇:運行時未定義的符號
