Struct std::process::Child [] [src]

pub struct Child {
    pub stdin: Option<ChildStdin>,
    pub stdout: Option<ChildStdout>,
    pub stderr: Option<ChildStderr>,
    // some fields omitted
}

Representation of a running or exited child process.

This structure is used to represent and manage child processes. A child process is created via the Command struct, which configures the spawning process and can itself be constructed using a builder-style interface.

Examples

fn main() { use std::process::Command; let mut child = Command::new("/bin/cat") .arg("file.txt") .spawn() .unwrap_or_else(|e| { panic!("failed to execute child: {}", e) }); let ecode = child.wait() .unwrap_or_else(|e| { panic!("failed to wait on child: {}", e) }); assert!(ecode.success()); }
use std::process::Command;

let mut child = Command::new("/bin/cat")
                        .arg("file.txt")
                        .spawn()
                        .unwrap_or_else(|e| { panic!("failed to execute child: {}", e) });

let ecode = child.wait()
                 .unwrap_or_else(|e| { panic!("failed to wait on child: {}", e) });

assert!(ecode.success());

Fields

stdin

The handle for writing to the child's stdin, if it has been captured

stdout

The handle for reading from the child's stdout, if it has been captured

stderr

The handle for reading from the child's stderr, if it has been captured

Methods

impl Child

fn kill(&mut self) -> Result<()>

Forces the child to exit. This is equivalent to sending a SIGKILL on unix platforms.

fn id(&self) -> u32

Returns the OS-assigned process identifier associated with this child.

fn wait(&mut self) -> Result<ExitStatus>

Waits for the child to exit completely, returning the status that it exited with. This function will continue to have the same return value after it has been called at least once.

The stdin handle to the child process, if any, will be closed before waiting. This helps avoid deadlock: it ensures that the child does not block waiting for input from the parent, while the parent waits for the child to exit.

fn wait_with_output(self) -> Result<Output>

Simultaneously waits for the child to exit and collect all remaining output on the stdout/stderr handles, returning an Output instance.

The stdin handle to the child process, if any, will be closed before waiting. This helps avoid deadlock: it ensures that the child does not block waiting for input from the parent, while the parent waits for the child to exit.