pub struct SharedChild { /* private fields */ }
Implementations§
Sourcepub fn spawn(command: &mut Command) -> Result<Self>
pub fn spawn(command: &mut Command) -> Result<Self>
Spawn a new SharedChild
from a
std::process::Command
.
Sourcepub fn new(child: Child) -> Result<Self>
pub fn new(child: Child) -> Result<Self>
Construct a new SharedChild
from an already spawned
std::process::Child
.
This constructor needs to know whether child
has already been waited on, and the only way
to find that out is to call
Child::try_wait
internally. If the child process is currently a zombie, that call will clean it up as a
side effect. The SharedChild::spawn
constructor doesn’t need to do this.
Sourcepub fn wait(&self) -> Result<ExitStatus>
pub fn wait(&self) -> Result<ExitStatus>
Wait for the child to exit, blocking the current thread, and return its exit status.
Sourcepub fn wait_timeout(&self, timeout: Duration) -> Result<Option<ExitStatus>>
pub fn wait_timeout(&self, timeout: Duration) -> Result<Option<ExitStatus>>
Wait for the child to exit, blocking the current thread, and return its exit status. Or if
the timeout passes before then, return Ok(None)
.
This polls the child at least once, and if the child has already exited it will return
Ok(Some(_))
even if the timeout is zero.
Sourcepub fn wait_deadline(&self, deadline: Instant) -> Result<Option<ExitStatus>>
pub fn wait_deadline(&self, deadline: Instant) -> Result<Option<ExitStatus>>
Wait for the child to exit, blocking the current thread, and return its exit status. Or if
the deadline passes before then, return Ok(None)
.
This polls the child at least once, and if the child has already exited it will return
Ok(Some(_))
even if the deadline is in the past.
Sourcepub fn try_wait(&self) -> Result<Option<ExitStatus>>
pub fn try_wait(&self) -> Result<Option<ExitStatus>>
Return the child’s exit status if it has already exited. If the child is still running,
return Ok(None)
.
Sourcepub fn kill(&self) -> Result<()>
pub fn kill(&self) -> Result<()>
Send a kill signal to the child. On Unix this sends SIGKILL, and you
should call wait
afterwards to avoid leaving a zombie. If the process
has already been waited on, this returns Ok(())
and does nothing.
Sourcepub fn into_inner(self) -> Child
pub fn into_inner(self) -> Child
Consume the SharedChild
and return the
std::process::Child
it
contains.
We never reap the child process except by calling
std::process::Child
methods on
it, so the child object’s inner state is correct, even if it was waited on while it was
shared.
Sourcepub fn take_stdin(&self) -> Option<ChildStdin>
pub fn take_stdin(&self) -> Option<ChildStdin>
Take the child’s
stdin
handle, if any.
This will only return Some
the first time it’s called, and then only if the Command
that created the child was configured with .stdin(Stdio::piped())
.
Sourcepub fn take_stdout(&self) -> Option<ChildStdout>
pub fn take_stdout(&self) -> Option<ChildStdout>
Take the child’s
stdout
handle, if any.
This will only return Some
the first time it’s called, and then only if the Command
that created the child was configured with .stdout(Stdio::piped())
.
Sourcepub fn take_stderr(&self) -> Option<ChildStderr>
pub fn take_stderr(&self) -> Option<ChildStderr>
Take the child’s
stderr
handle, if any.
This will only return Some
the first time it’s called, and then only if the Command
that created the child was configured with .stderr(Stdio::piped())
.