pub struct SpawnOptions<'a> { /* private fields */ }Expand description
Capabilities and policy needed only for one spawn operation.
Jobs are retained in call order, from the root Job to the innermost Job. The options borrow every capability; they never assume ownership of a Job, parent process, or pseudoconsole.
The borrow cannot escape the capability it protects:
ⓘ
use windows_spawn::{Command, Job, SpawnOptions};
let options;
{
let job = Job::create().unwrap();
options = SpawnOptions::new().job(&job);
}
Command::new("cmd.exe").spawn_with(options).unwrap();Implementations§
Source§impl<'a> SpawnOptions<'a>
impl<'a> SpawnOptions<'a>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates default per-spawn options.
Examples found in repository?
examples/managed_output.rs (line 11)
4fn main() -> std::io::Result<()> {
5 use windows_spawn::{Command, DropPolicy, SpawnOptions};
6
7 let mut command = Command::new(r"C:\Windows\System32\cmd.exe");
8 command
9 .args(["/D", "/S", "/C"])
10 .raw_arg("echo managed output");
11 let output = command.output_with(SpawnOptions::new().drop_policy(DropPolicy::KillTree))?;
12
13 assert!(output.status.success());
14 print!("{}", String::from_utf8_lossy(&output.stdout));
15 Ok(())
16}Sourcepub fn parent_process(self, parent: &'a ParentProcess) -> Self
pub fn parent_process(self, parent: &'a ParentProcess) -> Self
Chooses another process as the logical parent.
Sourcepub const fn mitigation(self, mitigation: MitigationPolicy) -> Self
pub const fn mitigation(self, mitigation: MitigationPolicy) -> Self
Applies a process-creation mitigation policy.
Sourcepub fn pseudoconsole<T: AsPseudoConsole>(self, pseudoconsole: &'a T) -> Self
pub fn pseudoconsole<T: AsPseudoConsole>(self, pseudoconsole: &'a T) -> Self
Attaches the child to a borrowed pseudoconsole.
Sourcepub const fn creation_flags(self, flags: CreationFlags) -> Self
pub const fn creation_flags(self, flags: CreationFlags) -> Self
Adds named process-creation flags.
Sourcepub const fn drop_policy(self, policy: DropPolicy) -> Self
pub const fn drop_policy(self, policy: DropPolicy) -> Self
Chooses the live-child drop policy.
Examples found in repository?
examples/managed_output.rs (line 11)
4fn main() -> std::io::Result<()> {
5 use windows_spawn::{Command, DropPolicy, SpawnOptions};
6
7 let mut command = Command::new(r"C:\Windows\System32\cmd.exe");
8 command
9 .args(["/D", "/S", "/C"])
10 .raw_arg("echo managed output");
11 let output = command.output_with(SpawnOptions::new().drop_policy(DropPolicy::KillTree))?;
12
13 assert!(output.status.success());
14 print!("{}", String::from_utf8_lossy(&output.stdout));
15 Ok(())
16}Trait Implementations§
Source§impl Debug for SpawnOptions<'_>
impl Debug for SpawnOptions<'_>
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for SpawnOptions<'a>
impl<'a> !Send for SpawnOptions<'a>
impl<'a> !Sync for SpawnOptions<'a>
impl<'a> !UnwindSafe for SpawnOptions<'a>
impl<'a> Freeze for SpawnOptions<'a>
impl<'a> Unpin for SpawnOptions<'a>
impl<'a> UnsafeUnpin for SpawnOptions<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more