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.
impl Command
The Command
type acts as a process builder for spawning programs that run in
an elevated context.
Example:
use runas::Command;
let status = Command::new("cmd").status();
Sourcepub fn new<S: AsRef<OsStr>>(program: S) -> Command
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.
Examples found in repository?
More examples
Sourcepub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Command
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Command
Add an argument to pass to the program.
Sourcepub fn args<S: AsRef<OsStr>>(&mut self, args: &[S]) -> &mut Command
pub fn args<S: AsRef<OsStr>>(&mut self, args: &[S]) -> &mut Command
Add multiple arguments to pass to the program.
Sourcepub fn show(&mut self, val: bool) -> &mut Command
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.
Sourcepub fn gui(&mut self, val: bool) -> &mut Command
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.
Sourcepub fn force_prompt(&mut self, val: bool) -> &mut Command
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.
Sourcepub fn status(&mut self) -> Result<ExitStatus>
pub fn status(&mut self) -> Result<ExitStatus>
Executes a command as a child process, waiting for it to finish and collecting its exit status.