Struct tauri_plugin_shell::process::Command
source · pub struct Command(/* private fields */);
Expand description
The type to spawn commands.
Implementations§
source§impl Command
impl Command
sourcepub fn env<K, V>(self, key: K, value: V) -> Self
pub fn env<K, V>(self, key: K, value: V) -> Self
Inserts or updates an explicit environment variable mapping.
sourcepub fn envs<I, K, V>(self, envs: I) -> Self
pub fn envs<I, K, V>(self, envs: I) -> Self
Adds or updates multiple environment variable mappings.
sourcepub fn current_dir<P: AsRef<Path>>(self, current_dir: P) -> Self
pub fn current_dir<P: AsRef<Path>>(self, current_dir: P) -> Self
Sets the working directory for the child process.
sourcepub fn spawn(self) -> Result<(Receiver<CommandEvent>, CommandChild), Error>
pub fn spawn(self) -> Result<(Receiver<CommandEvent>, CommandChild), Error>
Spawns the command.
§Examples
use tauri_plugin_shell::{process::CommandEvent, ShellExt};
tauri::Builder::default()
.setup(|app| {
let handle = app.handle().clone();
tauri::async_runtime::spawn(async move {
let (mut rx, mut child) = handle.shell().command("cargo")
.args(["tauri", "dev"])
.spawn()
.expect("Failed to spawn cargo");
let mut i = 0;
while let Some(event) = rx.recv().await {
if let CommandEvent::Stdout(line) = event {
println!("got: {}", String::from_utf8(line).unwrap());
i += 1;
if i == 4 {
child.write("message from Rust\n".as_bytes()).unwrap();
i = 0;
}
}
}
});
Ok(())
});
sourcepub async fn status(self) -> Result<ExitStatus, Error>
pub async fn status(self) -> Result<ExitStatus, Error>
Executes a command as a child process, waiting for it to finish and collecting its exit status. Stdin, stdout and stderr are ignored.
§Examples
use tauri_plugin_shell::ShellExt;
tauri::Builder::default()
.setup(|app| {
let status = tauri::async_runtime::block_on(async move { app.shell().command("which").args(["ls"]).status().await.unwrap() });
println!("`which` finished with status: {:?}", status.code());
Ok(())
});
sourcepub async fn output(self) -> Result<Output, Error>
pub async fn output(self) -> Result<Output, Error>
Executes the command as a child process, waiting for it to finish and collecting all of its output. Stdin is ignored.
§Examples
use tauri_plugin_shell::ShellExt;
tauri::Builder::default()
.setup(|app| {
let output = tauri::async_runtime::block_on(async move { app.shell().command("echo").args(["TAURI"]).output().await.unwrap() });
assert!(output.status.success());
assert_eq!(String::from_utf8(output.stdout).unwrap(), "TAURI");
Ok(())
});
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Command
impl Send for Command
impl Sync for Command
impl Unpin for Command
impl !UnwindSafe for Command
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