Skip to main content

Child

Struct Child 

Source
pub struct Child {
    pub stdin: Option<ChildStdin>,
    pub stdout: Option<ChildStdout>,
    pub stderr: Option<ChildStderr>,
    /* private fields */
}
Expand description

A spawned child process.

Fields§

§stdin: Option<ChildStdin>

The child’s stdin, if piped.

§stdout: Option<ChildStdout>

The child’s stdout, if piped.

§stderr: Option<ChildStderr>

The child’s stderr, if piped.

Implementations§

Source§

impl Child

Source

pub fn id(&self) -> u32

The child’s process id.

Source

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

Waits for the child’s exit. Its stdin, if piped, is closed first, so a child that reads it to its end can exit.

§Errors

When the exit cannot be watched, or the child was reaped by something else (ECHILD: SIGCHLD ignored, or a waitpid of the program’s own).

Source

pub fn try_wait(&mut self) -> Result<Option<ExitStatus>>

The child’s status if it exited, else None, without waiting.

§Errors

When the child’s state cannot be read.

Source

pub fn start_kill(&mut self) -> Result<()>

Starts ending the child, without waiting for it to go: SIGKILL on unix, TerminateProcess on Windows. A child that exited already is left alone.

§Errors

When the signal or the call fails.

Source

pub async fn kill(&mut self) -> Result<()>

Ends the child, as start_kill does, and waits for its exit.

use nuclei::process::Command;

let mut child = Command::new("sleep").arg("60").spawn()?;
child.kill().await?;
assert!(child.try_wait()?.is_some());
§Errors

As for start_kill and wait.

Source

pub async fn wait_with_output(self) -> Result<Output>

Waits for the child’s exit, collecting its stdout and stderr (those piped) until then. Its stdin, if piped, is closed first.

§Errors

As for wait, and when a pipe cannot be read.

Trait Implementations§

Source§

impl Debug for Child

Source§

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

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

impl Drop for Child

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !Freeze for Child

§

impl !RefUnwindSafe for Child

§

impl !UnwindSafe for Child

§

impl Send for Child

§

impl Sync for Child

§

impl Unpin for Child

§

impl UnsafeUnpin for Child

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.

§

impl<T> MaybeSend for T
where T: Send + ?Sized,

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.