tauri_plugin_shell::process

Struct Command

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

The type to spawn commands.

Implementations§

source§

impl Command

source

pub fn arg<S: AsRef<OsStr>>(self, arg: S) -> Self

Appends an argument to the command.

source

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

Appends arguments to the command.

source

pub fn env_clear(self) -> Self

Clears the entire environment map for the child process.

source

pub fn env<K, V>(self, key: K, value: V) -> Self
where K: AsRef<OsStr>, V: AsRef<OsStr>,

Inserts or updates an explicit environment variable mapping.

source

pub fn envs<I, K, V>(self, envs: I) -> Self
where I: IntoIterator<Item = (K, V)>, K: AsRef<OsStr>, V: AsRef<OsStr>,

Adds or updates multiple environment variable mappings.

source

pub fn current_dir<P: AsRef<Path>>(self, current_dir: P) -> Self

Sets the working directory for the child process.

source

pub fn set_raw_out(self, raw_out: bool) -> Self

Configures the reader to output bytes from the child process exactly as received

source

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(())
});
source

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(())
  });
source

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§

source§

impl Debug for Command

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Command> for Command

source§

fn from(cmd: Command) -> StdCommand

Converts to this type from the input type.

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.