pub struct Child {
pub stdin: Option<ChildStdin>,
pub stdout: Option<ChildStdout>,
pub stderr: Option<ChildStderr>,
/* private fields */
}Expand description
A running or exited process whose handle is owned exactly once.
Fields§
§stdin: Option<ChildStdin>A pipe connected to the child’s standard input, when requested.
stdout: Option<ChildStdout>A pipe connected to the child’s standard output, when requested.
stderr: Option<ChildStderr>A pipe connected to the child’s standard error, when requested.
Implementations§
Source§impl Child
impl Child
Sourcepub fn wait(&mut self) -> Result<ExitStatus>
pub fn wait(&mut self) -> Result<ExitStatus>
Waits for exit and caches the status.
§Errors
Returns an error if waiting or retrieving the exit code fails.
Examples found in repository?
4fn main() -> std::io::Result<()> {
5 use std::os::windows::io::AsHandle;
6
7 use windows_spawn::Command;
8
9 let mut command = Command::new(r"C:\Windows\System32\cmd.exe");
10 command.args(["/D", "/C", "exit /b 0"]);
11
12 let suspended = command.spawn_suspended()?;
13 println!("created suspended process {}", suspended.id());
14 let _process = suspended.as_handle();
15 let _primary_thread = suspended.primary_thread_handle();
16
17 let mut child = suspended.resume()?;
18 assert!(child.wait()?.success());
19 Ok(())
20}Sourcepub fn try_wait(&mut self) -> Result<Option<ExitStatus>>
pub fn try_wait(&mut self) -> Result<Option<ExitStatus>>
Checks for exit without blocking, returning the cached status thereafter.
§Errors
Returns an error if querying the process or its exit code fails.
Sourcepub fn wait_with_output(self) -> Result<Output>
pub fn wait_with_output(self) -> Result<Output>
Waits while draining both output pipes concurrently.
Under crate::DropPolicy::KillTree, descendants are terminated after
the root exits and before reader threads are joined. This guarantees EOF
even when a grandchild retained a pipe handle.
§Errors
Returns an error from process waiting, pipe reading, or Job termination.