boost::process::v1::std_out
// In header: <boost/process/v1/io.hpp> unspecified std_out;
此屬性允許設定子行程的輸出串流。
![]() |
注意事項 |
---|---|
語義與 std_err 相同 |
![]() |
注意事項 |
---|---|
|
檔案 I/O 簡單地將串流重新導向至檔案,可能的類型如下:
boost::process::v1::filesystem::path
std::basic_string<char_type>
const char_type*
FILE*
其中 char_type
可以是 char
或 wchar_t
。
明確地加入 FILE*,以便行程可以輕鬆地將子行程的輸出串流重新導向至行程的另一個輸出串流。也就是說
system("ls", std_out < stdin);
![]() |
警告 |
---|---|
如果啟動行程和子行程使用相同的輸入,將導致未定義的行為。 |
由於 C++ 實作不提供對控制代碼的存取權,因此像 system("ls", std_out > std::cerr)
這樣的語法是不可能的。
此屬性的有效表達式如下:
std_out < file; std_out = file;
如相關章節所述,boost.process 函式庫提供了一個 async_pipe 類別,可用於與子行程通訊。
![]() |
注意事項 |
---|---|
技術上,由於函式庫在此處未使用任何 asio 實作,async_pipe 的運作方式類似於同步管道。然而,如果行程已完成,非同步操作將不會結束,因為管道仍然保持開啟狀態。您可以使用 async_close 函數搭配 on_exit 來解決此問題。 |
使用管道的有效表達式如下:
std_out > pipe; std_out = pipe;
其中 pipe
的有效類型如下:
請注意,管道也可以在多個行程之間使用,如下所示:
pipe p; child c1("nm", "a.out", std_out>p); child c2("c++filt", std_in<p);
非同步管道 I/O 將通訊分類為由行程函式庫自動處理非同步操作。這表示將會建構一個管道,自動啟動 async_read/-write,並且子行程結束時也會關閉管道。
管道 I/O 的有效類型如下:
boost::asio::mutable_buffer
[31]
boost::asio::streambuf
std::future<std::vector<char>>
std::future<std::string>
使用管道的有效表達式如下:
std_out > buffer; std_out = buffer; std_err > buffer; std_err = buffer; (std_out & std_err) > buffer; (std_out & std_err) = buffer;
![]() |
注意事項 |
---|---|
|
![]() |
警告 |
---|---|
此功能需要包含 |