簡體   English   中英

如何使用 boost.process 重定向標准輸入和標准輸出

[英]how to redirect stdin and stdout using boost.process

我正在嘗試重定向子進程的標准輸入和標准輸出。 想用來自緩沖區的二進制數據填充進程的標准輸入並讀取它,(但現在我只需要知道有多少寫入標准輸出)

namespace  bp = boost::process;
bp::opstream in;
bp::ipstream out;

bp::child c(Cmd.c_str(), bp::std_out > out, bp::std_in < in);

in.write((char*)buffer,bufferSize);
integer_type totalRead = 0;
char a[10240];
while (out.read(a,10240))  totalRead += out.gcount();
c.terminate();

write 看起來是成功的,但程序卡在了 read-while 循環中,進程(子進程和父進程)在此期間保持空閑

工作代碼,看起來我必須關閉內部管道才能設置孩子的標准輸入 eof(孩子讀取標准輸入直到 eof(在我的情況下)):

namespace  bp = boost::process;
bp::opstream in;
bp::ipstream out;

bp::child c(Cmd.c_str(), bp::std_out > out, bp::std_in < in);    
in.write((char*)buffer,bufferSize);

in.pipe().close();

integer_type totalRead = 0;
char a[10240];
while (out.read(a,10240))  totalRead += out.gcount();
c.terminate();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM