# 1.0.0[−][src]Struct std::process::Child

    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.

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.

# 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());Run

## Fields

`stdin: Option<ChildStdin>`

The handle for writing to the child's standard input (stdin), if it has been captured.

`stdout: Option<ChildStdout>`

The handle for reading from the child's standard output (stdout), if it has been captured.

`stderr: Option<ChildStderr>`

The handle for reading from the child's standard error (stderr), if it has been captured.

## Methods

### `impl Child`[src]

#### `pub fn kill(&mut self) -> Result<()>`[src]

Forces the child process to exit. If the child has already exited, an `InvalidInput` error is returned.

The mapping to `ErrorKind`s is not part of the compatibility contract of the function, especially the `Other` kind might change to more specific kinds in the future.

This is equivalent to sending a SIGKILL on Unix platforms.

# Examples

Basic usage:

    use std::process::Command;

    let mut command = Command::new("yes");
    if let Ok(mut child) = command.spawn() {
        child.kill().expect("command wasn't running");
    } else {
        println!("yes command didn't start");
    }Run

#### `pub fn id(&self) -> u32`
1.3.0
[src]

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

# Examples

Basic usage:

    use std::process::Command;

    let mut command = Command::new("ls");
    if let Ok(child) = command.spawn() {
        println!("Child's id is {}", child.id());
    } else {
        println!("ls command didn't start");
    }Run

#### `pub fn wait(&mut self) -> Result<ExitStatus>`[src]

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.

# Examples

Basic usage:

    use std::process::Command;

    let mut command = Command::new("ls");
    if let Ok(mut child) = command.spawn() {
        child.wait().expect("command wasn't running");
        println!("Child has finished its execution!");
    } else {
        println!("ls command didn't start");
    }Run

#### `pub fn try_wait(&mut self) -> Result<Option<ExitStatus>>`
1.18.0
[src]

Attempts to collect the exit status of the child if it has already exited.

This function will not block the calling thread and will only check to see if the child process has exited or not. If the child has exited then on Unix the process id is reaped. This function is guaranteed to repeatedly return a successful exit status so long as the child has already exited.

If the child has exited, then `Ok(Some(status))` is returned. If the exit status is not available at this time then `Ok(None)` is returned. If an error occurs, then that error is returned.

Note that unlike `wait`, this function will not attempt to drop stdin.

# Examples

Basic usage:

    use std::process::Command;

    let mut child = Command::new("ls").spawn().unwrap();

    match child.try_wait() {
        Ok(Some(status)) => println!("exited with: {}", status),
        Ok(None) => {
            println!("status not ready yet, let's really wait");
            let res = child.wait();
            println!("result: {:?}", res);
        }
        Err(e) => println!("error attempting to wait: {}", e),
    }Run

#### `pub fn wait_with_output(self) -> Result<Output>`[src]

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 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());Run

## Trait Implementations

### `impl AsRawHandle for Child`
1.2.0
[src]

#### `fn as_raw_handle(&self) -> RawHandle`[src]

This is supported on Windows only.

Extracts the raw handle, without taking any ownership.

### `impl IntoRawHandle for Child`
1.4.0
[src]

#### `fn into_raw_handle(self) -> RawHandle`[src]

This is supported on Windows only.

Consumes this object, returning the raw underlying handle. Read more

### `impl Debug for Child`
1.16.0
[src]

#### `fn fmt(&self, f: &mut Formatter) -> Result`[src]

Formats the value using the given formatter. Read more

## Auto Trait Implementations

### `impl Send for Child`

### `impl Sync for Child`

## Blanket Implementations

### `impl<T> From for T`[src]

#### `fn from(t: T) -> T`[src]

Performs the conversion.

### `impl<T, U> TryFrom for T where
T: From<U>,` [src]

#### `type Error = !`

🔬 This is a nightly-only experimental API. (`try_from` #33417)

The type returned in the event of a conversion error.

#### `fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>`[src]

🔬 This is a nightly-only experimental API. (`try_from` #33417)

Performs the conversion.

### `impl<T, U> TryInto for T where
U: TryFrom<T>,` [src]

#### `type Error = <U as TryFrom<T>>::Error`

🔬 This is a nightly-only experimental API. (`try_from` #33417)

The type returned in the event of a conversion error.

#### `fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>`[src]

🔬 This is a nightly-only experimental API. (`try_from` #33417)

Performs the conversion.

### `impl<T, U> Into for T where
U: From<T>,` [src]

#### `fn into(self) -> U`[src]

Performs the conversion.

### `impl<T> Borrow for T where
T: ?Sized,` [src]

####
ⓘImportant traits for &'_ mut I

### Important traits for &'_ mut I

`impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'a, R: Read + ?Sized> Read for &'a mut Rimpl<'a, W: Write + ?Sized> Write for &'a mut W`
`fn borrow(&self) -> &T`[src]

Immutably borrows from an owned value. Read more

### `impl<T> BorrowMut for T where
T: ?Sized,` [src]

####
ⓘImportant traits for &'_ mut I

### Important traits for &'_ mut I

`impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<'a, R: Read + ?Sized> Read for &'a mut Rimpl<'a, W: Write + ?Sized> Write for &'a mut W`
`fn borrow_mut(&mut self) -> &mut T`[src]

Mutably borrows from an owned value. Read more

### `impl<T> Any for T where
T: 'static + ?Sized,` [src]

#### `fn get_type_id(&self) -> TypeId`[src]

🔬 This is a nightly-only experimental API. (`get_type_id` #27745)

this method will likely be replaced by an associated static

Gets the `TypeId` of `self`. Read more

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## 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`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)