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 running or exited process whose handle is owned exactly once.

Fields§

§stdin: Option<ChildStdin>

A pipe connected to the child’s standard input, when requested.

§stdout: Option<ChildStdout>

A pipe connected to the child’s standard output, when requested.

§stderr: Option<ChildStderr>

A pipe connected to the child’s standard error, when requested.

Implementations§

Source§

impl Child

Source

pub const fn id(&self) -> u32

Returns the process identifier captured at creation.

Source

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

Terminates the root process.

§Errors

Returns the operating-system error from TerminateProcess.

Source

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

Waits for exit and caches the status.

§Errors

Returns an error if waiting or retrieving the exit code fails.

Examples found in repository?
examples/suspended_inspection.rs (line 18)
4fn main() -> std::io::Result<()> {
5    use std::os::windows::io::AsHandle;
6
7    use windows_spawn::Command;
8
9    let mut command = Command::new(r"C:\Windows\System32\cmd.exe");
10    command.args(["/D", "/C", "exit /b 0"]);
11
12    let suspended = command.spawn_suspended()?;
13    println!("created suspended process {}", suspended.id());
14    let _process = suspended.as_handle();
15    let _primary_thread = suspended.primary_thread_handle();
16
17    let mut child = suspended.resume()?;
18    assert!(child.wait()?.success());
19    Ok(())
20}
Source

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

Checks for exit without blocking, returning the cached status thereafter.

§Errors

Returns an error if querying the process or its exit code fails.

Source

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

Waits while draining both output pipes concurrently.

Under crate::DropPolicy::KillTree, descendants are terminated after the root exits and before reader threads are joined. This guarantees EOF even when a grandchild retained a pipe handle.

§Errors

Returns an error from process waiting, pipe reading, or Job termination.

Trait Implementations§

Source§

impl AsHandle for Child

Source§

fn as_handle(&self) -> BorrowedHandle<'_>

Borrows the handle. Read more
Source§

impl Debug for Child

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Child

§

impl RefUnwindSafe for Child

§

impl Send for Child

§

impl Sync for Child

§

impl Unpin for Child

§

impl UnsafeUnpin for Child

§

impl UnwindSafe 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.

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.