本文简要介绍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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。