[][src]Struct tokio::net::process::Child

#[must_use = "futures do nothing unless polled"]
pub struct Child { /* fields omitted */ }

Representation of a child process spawned onto an event loop.

This type is also a future which will yield the ExitStatus of the underlying child process. A Child here also provides access to information like the OS-assigned identifier and the stdio streams.

Note: The behavior of drop on a child in this crate is different than the behavior of the standard library. If a tokio_net::process::Child is dropped before the process finishes then the process will be terminated. In the standard library, however, the process continues executing. This is done because futures in general take drop as a sign of cancellation, and this Child is itself a future. If you'd like to run a process in the background, though, you may use the forget method.

Methods

impl Child[src]

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

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

pub fn kill(&mut self) -> Result<(), Error>[src]

Forces the child to exit.

This is equivalent to sending a SIGKILL on unix platforms.

pub fn stdin(&mut self) -> &mut Option<ChildStdin>[src]

Returns a handle for writing to the child's stdin, if it has been captured.

pub fn stdout(&mut self) -> &mut Option<ChildStdout>[src]

Returns a handle for reading from the child's stdout, if it has been captured.

pub fn stderr(&mut self) -> &mut Option<ChildStderr>[src]

Returns a handle for reading from the child's stderr, if it has been captured.

pub fn wait_with_output(
    __arg0: Self
) -> impl Future<Output = Result<Output, Error>>
[src]

Returns a future that will resolve to an Output, containing the exit status, stdout, and stderr of the child process.

The returned future will 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 Output it is necessary to create new pipes between parent and child. Use stdout(Stdio::piped()) or stderr(Stdio::piped()), respectively, when creating a Command.

pub fn forget(self)[src]

Drop this Child without killing the underlying process.

Normally a Child is killed if it's still alive when dropped, but this method will ensure that the child may continue running once the Child instance is dropped.

Note: this method may leak OS resources depending on your platform. To ensure resources are eventually cleaned up, consider sending the Child instance into an event loop as an alternative to this method.


let child = Command::new("echo").arg("hello").arg("world")
                    .spawn()
                    .expect("failed to spawn");

tokio::spawn(async {
  let _ = child.await;
});

Trait Implementations

impl Future for Child[src]

type Output = Result<ExitStatus, Error>

The type of value produced on completion.

impl Debug for Child[src]

Auto Trait Implementations

impl Send for Child

impl Unpin for Child

impl Sync for Child

impl !UnwindSafe for Child

impl !RefUnwindSafe for Child

Blanket Implementations

impl<T> FutureExt for T where
    T: Future + ?Sized
[src]

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

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

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

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

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

impl<F, T, E> TryFuture for F where
    F: Future<Output = Result<T, E>> + ?Sized
[src]

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future

impl<T> FutureExt for T where
    T: Future + ?Sized
[src]

impl<Fut> TryFutureExt for Fut where
    Fut: TryFuture + ?Sized
[src]