Struct SharedChild

Source
pub struct SharedChild { /* private fields */ }

Implementations§

Source§

impl SharedChild

Source

pub fn spawn(command: &mut Command) -> Result<Self>

Spawn a new SharedChild from a std::process::Command.

Source

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.

Source

pub fn id(&self) -> u32

Return the child process ID.

Source

pub fn wait(&self) -> Result<ExitStatus>

Wait for the child to exit, blocking the current thread, and return its exit status.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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()).

Source

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()).

Source

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()).

Trait Implementations§

Source§

impl Debug for SharedChild

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl SharedChildExt for SharedChild

Source§

fn send_signal(&self, signal: c_int) -> Result<()>

Send a signal to the child process with libc::kill. If the process has already been waited on, this returns Ok(()) and does nothing.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.