Struct CreateProcessW::Command

source ·
pub struct Command { /* private fields */ }
Expand description

A process builder, providing control over how a new process should be spawned.

Implementations§

source§

impl Command

source

pub fn new(command: impl Into<OsString>) -> Self

Create a new Command, with the following default configuration:

  • Inherit handles of the calling process.
  • Inherit the current drive and directory of the calling process.

Builder methods are provided to change these defaults and otherwise configure the process.

§Examples
use CreateProcessW::Command;

Command::new("notepad.exe")
    .spawn()
    .expect("notepad failed to start");

Equivalent to the lpCommandLine parameter of the CreateProcessW function.

source

pub fn inherit_handles(&mut self, inherit: bool) -> &mut Self

Enable/disable handles inherance.

If this parameter is true, each inheritable handle in the calling process is inherited by the new process. If the parameter is false, the handles are not inherited. Note that inherited handles have the same value and access rights as the original handles.

Equivalent to the bInheritHandles parameter of the CreateProcessW function.

source

pub fn current_dir(&mut self, dir: impl Into<PathBuf>) -> &mut Self

Sets the working directory for the child process.

It’s the full path to the current directory for the process. Note that you can use a raw string to avoid error when copy-pasting the path.

§Examples
use CreateProcessW::Command;

let check = Command::new("cargo.exe check")
    .current_dir(r"C:\Users\<user>\repos\<repo_name>")
    .status()
    .expect("cargo check command failed");

Equivalent to the lpCurrentDirectory parameter of the CreateProcessW function.

source

pub fn spawn(&mut self) -> Result<Child, Error>

Executes the command as a child process, returning a handle to it.

§Examples
use CreateProcessW::Command;

Command::new("notepad.exe")
    .spawn()
    .expect("notepad failed to start");
source

pub fn status(&mut self) -> Result<ExitStatus, Error>

Executes a command as a child process, waiting for it to finish and collecting its status.

§Examples
use CreateProcessW::Command;

let status = Command::new("notepad.exe")
    .status()
    .expect("failed to execute process");

println!("process finished with: {}", status.code());

assert!(status.success());

Trait Implementations§

source§

impl Debug for Command

source§

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

Formats the value using the given formatter. 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>,

§

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

§

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.