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
impl SuspendedChild
Sourcepub fn id(&self) -> u32
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?
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}Sourcepub fn primary_thread_handle(&self) -> BorrowedHandle<'_>
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?
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}Sourcepub fn resume(self) -> Result<Child>
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?
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}