Command

Struct Command 

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

A process builder for elevated execution

Implementations§

Source§

impl Command

The Command type acts as a process builder for spawning programs that run in an elevated context.

Example:

use run_as::Command;
let status = Command::new("cmd").status();
Source

pub fn new<S: AsRef<OsStr>>(program: S) -> Command

Creates a new command type for a given program.

The default configuration is to spawn without arguments, to be visible and to not be launched from a GUI context.

Source

pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Command

Add an argument to pass to the program.

Source

pub fn args<I, S>(&mut self, args: I) -> &mut Command
where I: IntoIterator<Item = S>, S: AsRef<OsStr>,

Add multiple arguments to pass to the program.

Source

pub fn show(&mut self, val: bool) -> &mut Command

Controls the visibility of the program on supported platforms. The default is to launch the program visible.

Source

pub fn gui(&mut self, val: bool) -> &mut Command

Controls the GUI context. The default behavior is to assume that the program is launched from a command line (not using a GUI). This primarily controls how the elevation prompt is rendered. On some platforms like Windows the elevation prompt is always a GUI element.

If the preferred mode is not available it falls back to the other automatically.

Source

pub fn force_prompt(&mut self, val: bool) -> &mut Command

Can disable the prompt forcing for supported platforms. Mostly this allows sudo on unix platforms to not prompt for a password.

Source

pub fn wait_to_complete(&mut self, val: bool) -> &mut Command

Controls whether to wait for the command to complete. The default is to wait. If set to false the command is started and the function returns immediately. The exit status in that case is always reported as success.

Source

pub fn pkexec_timeout(&mut self, val: Option<Duration>) -> &mut Command

Sets the timeout for pkexec on Linux.

Source

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

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

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.