pub struct Command { /* private fields */ }
Available on crate feature
process-command-api
only.Expand description
The type to spawn commands.
Implementations§
source§impl Command
impl Command
sourcepub fn new<S: Into<String>>(program: S) -> Self
pub fn new<S: Into<String>>(program: S) -> Self
Creates a new Command for launching the given program.
sourcepub fn new_sidecar<S: Into<String>>(program: S) -> Result<Self>
pub fn new_sidecar<S: Into<String>>(program: S) -> Result<Self>
Creates a new Command for launching the given sidecar program.
A sidecar program is a embedded external binary in order to make your application work or to prevent users having to install additional dependencies (e.g. Node.js, Python, etc).
sourcepub fn envs(self, env: HashMap<String, String>) -> Self
pub fn envs(self, env: HashMap<String, String>) -> Self
Adds or updates multiple environment variable mappings.
sourcepub fn current_dir(self, current_dir: PathBuf) -> Self
pub fn current_dir(self, current_dir: PathBuf) -> Self
Sets the working directory for the child process.
sourcepub fn encoding(self, encoding: &'static Encoding) -> Self
pub fn encoding(self, encoding: &'static Encoding) -> Self
Sets the character encoding for stdout/stderr.
sourcepub fn spawn(self) -> Result<(Receiver<CommandEvent>, CommandChild)>
pub fn spawn(self) -> Result<(Receiver<CommandEvent>, CommandChild)>
Spawns the command.
§Examples
use tauri::api::process::{Command, CommandEvent};
tauri::async_runtime::spawn(async move {
let (mut rx, mut child) = Command::new("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: {}", line);
i += 1;
if i == 4 {
child.write("message from Rust\n".as_bytes()).unwrap();
i = 0;
}
}
}
});
sourcepub fn status(self) -> Result<ExitStatus>
pub fn status(self) -> Result<ExitStatus>
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::api::process::Command;
let status = Command::new("which").args(["ls"]).status().unwrap();
println!("`which` finished with status: {:?}", status.code());
sourcepub fn output(self) -> Result<Output>
pub fn output(self) -> Result<Output>
Executes the command as a child process, waiting for it to finish and collecting all of its output. Stdin is ignored.
§Examples
use tauri::api::process::Command;
let output = Command::new("echo").args(["TAURI"]).output().unwrap();
assert!(output.status.success());
assert_eq!(output.stdout, "TAURI");
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Command
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