pub struct Child { /* private fields */ }
Expand description
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 atokio_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 takedrop
as a sign of cancellation, and thisChild
is itself a future. If you’d like to run a process in the background, though, you may use theforget
method.
Implementations§
Source§impl Child
impl Child
Sourcepub fn kill(&mut self) -> Result<()>
pub fn kill(&mut self) -> Result<()>
Forces the child to exit.
This is equivalent to sending a SIGKILL on unix platforms.
Sourcepub fn stdin(&mut self) -> &mut Option<ChildStdin>
pub fn stdin(&mut self) -> &mut Option<ChildStdin>
Returns a handle for writing to the child’s stdin, if it has been captured
Sourcepub fn stdout(&mut self) -> &mut Option<ChildStdout>
pub fn stdout(&mut self) -> &mut Option<ChildStdout>
Returns a handle for writing to the child’s stdout, if it has been captured
Sourcepub fn stderr(&mut self) -> &mut Option<ChildStderr>
pub fn stderr(&mut self) -> &mut Option<ChildStderr>
Returns a handle for writing to the child’s stderr, if it has been captured
Sourcepub fn wait_with_output(self) -> WaitWithOutput
pub fn wait_with_output(self) -> WaitWithOutput
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
.
Sourcepub fn forget(self)
pub fn forget(self)
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_async()
.expect("failed to spawn");
let do_cleanup = child.map(|_| ()) // Ignore result
.map_err(|_| ()); // Ignore errors
tokio::spawn(do_cleanup);
Trait Implementations§
Source§impl Future for Child
impl Future for Child
Source§type Item = ExitStatus
type Item = ExitStatus
Source§type Error = Error
type Error = Error
Source§fn poll(&mut self) -> Poll<ExitStatus, Error>
fn poll(&mut self) -> Poll<ExitStatus, Error>
Source§fn wait(self) -> Result<Self::Item, Self::Error>where
Self: Sized,
fn wait(self) -> Result<Self::Item, Self::Error>where
Self: Sized,
Source§fn map<F, U>(self, f: F) -> Map<Self, F>
fn map<F, U>(self, f: F) -> Map<Self, F>
Source§fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
Source§fn from_err<E>(self) -> FromErr<Self, E>
fn from_err<E>(self) -> FromErr<Self, E>
From
for
this future’s Error
, returning a new future. Read moreSource§fn then<F, B>(self, f: F) -> Then<Self, B, F>
fn then<F, B>(self, f: F) -> Then<Self, B, F>
f
. Read moreSource§fn and_then<F, B>(self, f: F) -> AndThen<Self, B, F>
fn and_then<F, B>(self, f: F) -> AndThen<Self, B, F>
Source§fn or_else<F, B>(self, f: F) -> OrElse<Self, B, F>
fn or_else<F, B>(self, f: F) -> OrElse<Self, B, F>
Source§fn select<B>(self, other: B) -> Select<Self, <B as IntoFuture>::Future>
fn select<B>(self, other: B) -> Select<Self, <B as IntoFuture>::Future>
Source§fn select2<B>(self, other: B) -> Select2<Self, <B as IntoFuture>::Future>where
B: IntoFuture,
Self: Sized,
fn select2<B>(self, other: B) -> Select2<Self, <B as IntoFuture>::Future>where
B: IntoFuture,
Self: Sized,
Source§fn join<B>(self, other: B) -> Join<Self, <B as IntoFuture>::Future>
fn join<B>(self, other: B) -> Join<Self, <B as IntoFuture>::Future>
Source§fn join3<B, C>(
self,
b: B,
c: C,
) -> Join3<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future>
fn join3<B, C>( self, b: B, c: C, ) -> Join3<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future>
join
, but with more futures.Source§fn join4<B, C, D>(
self,
b: B,
c: C,
d: D,
) -> Join4<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future, <D as IntoFuture>::Future>where
B: IntoFuture<Error = Self::Error>,
C: IntoFuture<Error = Self::Error>,
D: IntoFuture<Error = Self::Error>,
Self: Sized,
fn join4<B, C, D>(
self,
b: B,
c: C,
d: D,
) -> Join4<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future, <D as IntoFuture>::Future>where
B: IntoFuture<Error = Self::Error>,
C: IntoFuture<Error = Self::Error>,
D: IntoFuture<Error = Self::Error>,
Self: Sized,
join
, but with more futures.Source§fn join5<B, C, D, E>(
self,
b: B,
c: C,
d: D,
e: E,
) -> Join5<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future, <D as IntoFuture>::Future, <E as IntoFuture>::Future>where
B: IntoFuture<Error = Self::Error>,
C: IntoFuture<Error = Self::Error>,
D: IntoFuture<Error = Self::Error>,
E: IntoFuture<Error = Self::Error>,
Self: Sized,
fn join5<B, C, D, E>(
self,
b: B,
c: C,
d: D,
e: E,
) -> Join5<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future, <D as IntoFuture>::Future, <E as IntoFuture>::Future>where
B: IntoFuture<Error = Self::Error>,
C: IntoFuture<Error = Self::Error>,
D: IntoFuture<Error = Self::Error>,
E: IntoFuture<Error = Self::Error>,
Self: Sized,
join
, but with more futures.Source§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
Source§fn flatten(self) -> Flatten<Self>
fn flatten(self) -> Flatten<Self>
Source§fn flatten_stream(self) -> FlattenStream<Self>
fn flatten_stream(self) -> FlattenStream<Self>
Source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
poll
will never again be called once it has
completed. Read more