本文簡要介紹rust語言中 std::process::Child.wait_with_output
的用法。
用法
pub fn wait_with_output(self) -> Result<Output>
同時等待子進程退出並收集 stdout/stderr 句柄上的所有剩餘輸出,返回 Output
實例。
子進程的 stdin 句柄(如果有)將在等待之前關閉。這有助於避免死鎖:它確保子級在父級等待子級退出時不會阻塞等待父級的輸入。
默認情況下,標準輸入、標準輸出和標準錯誤是從父級繼承的。為了將輸出捕獲到此Result<Output>
中,有必要在父子節點之間創建新管道。分別使用 stdout(Stdio::piped())
或 stderr(Stdio::piped())
。
例子
use std::process::{Command, Stdio};
let child = Command::new("/bin/cat")
.arg("file.txt")
.stdout(Stdio::piped())
.spawn()
.expect("failed to execute child");
let output = child
.wait_with_output()
.expect("failed to wait on child");
assert!(output.status.success());
相關用法
- Rust Child.wait用法及代碼示例
- Rust Child.kill用法及代碼示例
- Rust Child.id用法及代碼示例
- Rust Child.try_wait用法及代碼示例
- Rust Child用法及代碼示例
- Rust Chars.as_str用法及代碼示例
- Rust Chain.get_ref用法及代碼示例
- Rust Chain.get_mut用法及代碼示例
- Rust ChunksExact用法及代碼示例
- Rust Chain用法及代碼示例
- Rust CharIndices.offset用法及代碼示例
- Rust Chunks用法及代碼示例
- Rust ChunksMut用法及代碼示例
- Rust ChunksExactMut用法及代碼示例
- Rust Chain.into_inner用法及代碼示例
- Rust CStr.into_c_string用法及代碼示例
- Rust Cursor.new用法及代碼示例
- Rust Condvar.notify_all用法及代碼示例
- Rust Cursor.remaining_slice用法及代碼示例
- Rust Command.args用法及代碼示例
- Rust Condvar.wait用法及代碼示例
- Rust CString.into_bytes用法及代碼示例
- Rust CStr.from_bytes_with_nul用法及代碼示例
- Rust Cow.is_owned用法及代碼示例
- Rust Cow用法及代碼示例
注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 std::process::Child.wait_with_output。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。