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 run_as::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.
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<I, S>(&mut self, args: I) -> &mut Command
pub fn args<I, S>(&mut self, args: I) -> &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 wait_to_complete(&mut self, val: bool) -> &mut Command
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.
Sourcepub fn pkexec_timeout(&mut self, val: Option<Duration>) -> &mut Command
pub fn pkexec_timeout(&mut self, val: Option<Duration>) -> &mut Command
Sets the timeout for pkexec on Linux.
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.