pub struct ChildWrapper { /* private fields */ }
Expand description
Wraps a std::process::Child
to coordinate state between std
and
wait_timeout
.
This is necessary because the completion of a call to
wait_timeout::ChildExt::wait_timeout
leaves the Child
in an
inconsistent state, as it does not know the child has exited, and on Unix
may end up referencing another process.
Documentation for this struct’s methods is largely copied from the Rust std docs.
Implementations§
Source§impl ChildWrapper
impl ChildWrapper
Sourcepub fn inner(&self) -> &Child
pub fn inner(&self) -> &Child
Return a reference to the inner std::process::Child
.
Use care on the returned object, as it does not necessarily reference the correct process unless you know the child process has not exited and no wait calls have succeeded.
Sourcepub fn inner_mut(&mut self) -> &mut Child
pub fn inner_mut(&mut self) -> &mut Child
Return a mutable reference to the inner std::process::Child
.
Use care on the returned object, as it does not necessarily reference the correct process unless you know the child process has not exited and no wait calls have succeeded.
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.
If the process has already been reaped by this handle, returns a
NotFound
error.
Sourcepub fn id(&self) -> u32
pub fn id(&self) -> u32
Returns the OS-assigned processor identifier associated with this child.
This succeeds even if the child has already been reaped. In this case, the process id may reference no process at all or even an unrelated process.
Sourcepub fn wait(&mut self) -> Result<ExitStatusWrapper>
pub fn wait(&mut self) -> Result<ExitStatusWrapper>
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.
If the child process has already been reaped, returns its exit status without blocking.
Sourcepub fn try_wait(&mut self) -> Result<Option<ExitStatusWrapper>>
pub fn try_wait(&mut self) -> Result<Option<ExitStatusWrapper>>
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 advisorily 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.
Sourcepub fn wait_with_output(self) -> Result<Output>
pub fn wait_with_output(self) -> Result<Output>
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
the context of rusty_fork
, they are by default redirected to a file.)
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.
If the process has already been reaped, returns a NotFound
error.
Sourcepub fn wait_timeout(
&mut self,
dur: Duration,
) -> Result<Option<ExitStatusWrapper>>
pub fn wait_timeout( &mut self, dur: Duration, ) -> Result<Option<ExitStatusWrapper>>
Wait for the child to exit, but only up to the given maximum duration.
If the process has already been reaped, returns its exit status
immediately. Otherwise, if the process terminates within the duration,
returns Ok(Sone(..))
, or Ok(None)
otherwise.
This is only present if the “timeout” feature is enabled.