Skip to main content

SpawnOptions

Struct SpawnOptions 

Source
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>

Source

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}
Source

pub fn job(self, job: &'a Job) -> Self

Appends a Job, preserving root-to-inner ordering.

Source

pub fn parent_process(self, parent: &'a ParentProcess) -> Self

Chooses another process as the logical parent.

Source

pub const fn mitigation(self, mitigation: MitigationPolicy) -> Self

Applies a process-creation mitigation policy.

Source

pub fn pseudoconsole<T: AsPseudoConsole>(self, pseudoconsole: &'a T) -> Self

Attaches the child to a borrowed pseudoconsole.

Source

pub const fn creation_flags(self, flags: CreationFlags) -> Self

Adds named process-creation flags.

Source

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<'_>

Source§

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

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

impl Default for SpawnOptions<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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