# Struct bitflags::__core::process::Child [−] [src]

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

1.0.0

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

    use std::process::Command;

    let mut child = Command::new("/bin/cat")
                            .arg("file.txt")
                            .spawn()
                            .expect("failed to execute child");

    let ecode = child.wait()
                     .expect("failed to wait on child");

    assert!(ecode.success());

# Note

Take note that there is no implementation of `Drop` for child processes, so if you do not ensure the `Child` has exited then it will continue to run, even after the `Child` handle to the child process has gone out of scope.

Calling `wait` (or other functions that wrap around it) will make the parent process wait until the child has actually exited before continuing.

## 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<(), Error>`

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

#### `fn id(&self) -> u32` 1.3.0

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

#### `fn wait(&mut self) -> Result<ExitStatus, Error>`

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, Error>`

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.

By default, stdin, stdout and stderr are inherited from the parent. In order to capture the output into this `Result<Output>` it is necessary to create new pipes between parent and child. Use `stdout(Stdio::piped())` or `stderr(Stdio::piped())`, respectively.

# Examples

    use std::process::{Command, Stdio};

    let mut child = Command::new("/bin/cat")
                            .arg("file.txt")
                            .stdout(Stdio::piped())
                            .spawn()
                            .expect("failed to execute child");

    let ecode = child.wait_with_output()
                     .expect("failed to wait on child");

    assert!(ecode.status.success());

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)