Struct super_shell::RootShell
source · pub struct RootShell { /* private fields */ }
Expand description
Represents a shell with root privileges.
Implementations§
source§impl RootShell
impl RootShell
Implementation of RootShell
sourcepub fn new() -> Option<Self>
pub fn new() -> Option<Self>
Creates a new root shell. Defaults to pkexec as super user provider and sh as shell. Returns None if the root shell could not be created.
Example
use super_shell::RootShell;
let mut root_shell = RootShell::new().expect("Failed to crate root shell");
println!("{}", root_shell.execute("echo Hello $USER"));
sourcepub fn new_custom(super_user_provider: &str, shell: &str) -> Option<Self>
pub fn new_custom(super_user_provider: &str, shell: &str) -> Option<Self>
Creates a new root shell with the specified super user provider and shell. Returns None if the root shell could not be created. sudo as an interactive super user provider is currently not supported.
Parameter
super_user_provider
- The command to use to get super user privilegesshell
- The shell to use
Example
use super_shell::RootShell;
let mut root_shell = RootShell::new_custom("gksu", "bash").expect("Failed to crate root shell");
println!("{}", root_shell.execute("echo Hello $USER"));
sourcepub fn execute(&mut self, command: impl AsRef<str>) -> String
pub fn execute(&mut self, command: impl AsRef<str>) -> String
Executes a command in the root shell and returns the output trimmed. Blocks the current thread until the command is finished.
Parameter
command
- The command to execute
Example
use super_shell::RootShell;
let mut root_shell = RootShell::new().expect("Failed to crate root shell");
assert!(root_shell.execute("echo Hello $USER").trim().eq("Hello root"));
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for RootShell
impl Send for RootShell
impl Sync for RootShell
impl Unpin for RootShell
impl UnwindSafe for RootShell
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more