Skip to main content

SuspendedChild

Struct SuspendedChild 

Source
pub struct SuspendedChild { /* private fields */ }
Expand description

A process whose primary thread has not yet been resumed.

Dropping this value without resuming always terminates the process. The consuming transition makes a second resume unrepresentable:

use windows_spawn::Command;

let mut command = Command::new("cmd.exe");
let suspended = command.spawn_suspended().unwrap();
let _child = suspended.resume().unwrap();
let _second = suspended.resume().unwrap();

Implementations§

Source§

impl SuspendedChild

Source

pub fn id(&self) -> u32

Returns the process identifier captured at creation.

§Panics

Panics only if an internal ownership invariant was violated and the process was removed before this suspended value was consumed.

Examples found in repository?
examples/suspended_inspection.rs (line 13)
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 primary_thread_handle(&self) -> BorrowedHandle<'_>

Borrows the suspended process’s primary thread handle.

This handle is available for supported thread configuration and inspection before Self::resume consumes the suspended state.

Examples found in repository?
examples/suspended_inspection.rs (line 15)
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 resume(self) -> Result<Child>

Resumes the primary thread and transitions to an ordinary Child.

§Errors

Returns the operating-system error when the primary thread cannot be resumed. It also returns InvalidData when external suspension or resumption changed the expected suspend count of exactly one. The process is terminated during either rollback.

Examples found in repository?
examples/suspended_inspection.rs (line 17)
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}

Trait Implementations§

Source§

impl AsHandle for SuspendedChild

Source§

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

Borrows the handle. Read more
Source§

impl Debug for SuspendedChild

Source§

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

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

impl Drop for SuspendedChild

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§

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.