Struct async_process::Command [−][src]
A builder for spawning processes.
Examples
use async_process::Command; let output = if cfg!(target_os = "windows") { Command::new("cmd").args(&["/C", "echo hello"]).output().await? } else { Command::new("sh").arg("-c").arg("echo hello").output().await? };
Implementations
impl Command
[src]
pub fn new<S: AsRef<OsStr>>(program: S) -> Command
[src]
Constructs a new Command
for launching program
.
The initial configuration (the working directory and environment variables) is inherited from the current process.
Examples
use async_process::Command; let mut cmd = Command::new("ls");
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Command
[src]
Adds a single argument to pass to the program.
Examples
use async_process::Command; let mut cmd = Command::new("echo"); cmd.arg("hello"); cmd.arg("world");
pub fn args<I, S>(&mut self, args: I) -> &mut Command where
I: IntoIterator<Item = S>,
S: AsRef<OsStr>,
[src]
I: IntoIterator<Item = S>,
S: AsRef<OsStr>,
Adds multiple arguments to pass to the program.
Examples
use async_process::Command; let mut cmd = Command::new("echo"); cmd.args(&["hello", "world"]);
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Command where
K: AsRef<OsStr>,
V: AsRef<OsStr>,
[src]
K: AsRef<OsStr>,
V: AsRef<OsStr>,
Configures an environment variable for the new process.
Note that environment variable names are case-insensitive (but case-preserving) on Windows, and case-sensitive on all other platforms.
Examples
use async_process::Command; let mut cmd = Command::new("ls"); cmd.env("PATH", "/bin");
pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Command where
I: IntoIterator<Item = (K, V)>,
K: AsRef<OsStr>,
V: AsRef<OsStr>,
[src]
I: IntoIterator<Item = (K, V)>,
K: AsRef<OsStr>,
V: AsRef<OsStr>,
Configures multiple environment variables for the new process.
Note that environment variable names are case-insensitive (but case-preserving) on Windows, and case-sensitive on all other platforms.
Examples
use async_process::Command; let mut cmd = Command::new("ls"); cmd.envs(vec![("PATH", "/bin"), ("TERM", "xterm-256color")]);
pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Command
[src]
Removes an environment variable mapping.
Examples
use async_process::Command; let mut cmd = Command::new("ls"); cmd.env_remove("PATH");
pub fn env_clear(&mut self) -> &mut Command
[src]
Removes all environment variable mappings.
Examples
use async_process::Command; let mut cmd = Command::new("ls"); cmd.env_clear();
pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Command
[src]
Configures the working directory for the new process.
Examples
use async_process::Command; let mut cmd = Command::new("ls"); cmd.current_dir("/");
pub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command
[src]
Configures the standard input (stdin) for the new process.
Examples
use async_process::{Command, Stdio}; let mut cmd = Command::new("cat"); cmd.stdin(Stdio::null());
pub fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command
[src]
Configures the standard output (stdout) for the new process.
Examples
use async_process::{Command, Stdio}; let mut cmd = Command::new("ls"); cmd.stdout(Stdio::piped());
pub fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command
[src]
Configures the standard error (stderr) for the new process.
Examples
use async_process::{Command, Stdio}; let mut cmd = Command::new("ls"); cmd.stderr(Stdio::piped());
pub fn reap_on_drop(&mut self, reap_on_drop: bool) -> &mut Command
[src]
Configures whether to reap the zombie process when Child
is dropped.
When the process finishes, it becomes a “zombie” and some resources associated with it
remain until Child::try_status()
, Child::status()
, or Child::output()
collects
its exit code.
If its exit code is never collected, the resources may leak forever. This crate has a background thread named “async-process” that collects such “zombie” processes and then “reaps” them, thus preventing the resource leaks.
The default value of this option is true
.
Examples
use async_process::{Command, Stdio}; let mut cmd = Command::new("cat"); cmd.reap_on_drop(false);
pub fn kill_on_drop(&mut self, kill_on_drop: bool) -> &mut Command
[src]
Configures whether to kill the process when Child
is dropped.
The default value of this option is false
.
Examples
use async_process::{Command, Stdio}; let mut cmd = Command::new("cat"); cmd.kill_on_drop(true);
pub fn spawn(&mut self) -> Result<Child>
[src]
Executes the command and returns the Child
handle to it.
If not configured, stdin, stdout and stderr will be set to Stdio::inherit()
.
After spawning the process, stdin, stdout, and stderr become unconfigured again.
Examples
use async_process::Command; let child = Command::new("ls").spawn()?;
pub fn status(&mut self) -> impl Future<Output = Result<ExitStatus>>
[src]
Executes the command, waits for it to exit, and returns the exit status.
If not configured, stdin, stdout and stderr will be set to Stdio::inherit()
.
After spawning the process, stdin, stdout, and stderr become unconfigured again.
Examples
use async_process::Command; let status = Command::new("cp") .arg("a.txt") .arg("b.txt") .status() .await?;
pub fn output(&mut self) -> impl Future<Output = Result<Output>>
[src]
Executes the command and collects its output.
If not configured, stdin will be set to Stdio::null()
, and stdout and stderr will be
set to Stdio::piped()
.
After spawning the process, stdin, stdout, and stderr become unconfigured again.
Examples
use async_process::Command; let output = Command::new("cat") .arg("a.txt") .output() .await?;
Trait Implementations
impl CommandExt for Command
[src]
fn uid(&mut self, id: u32) -> &mut Command
[src]
fn gid(&mut self, id: u32) -> &mut Command
[src]
unsafe fn pre_exec<F>(&mut self, f: F) -> &mut Command where
F: FnMut() -> Result<()> + Send + Sync + 'static,
[src]
F: FnMut() -> Result<()> + Send + Sync + 'static,
fn exec(&mut self) -> Error
[src]
fn arg0<S>(&mut self, arg: S) -> &mut Command where
S: AsRef<OsStr>,
[src]
S: AsRef<OsStr>,
impl Debug for Command
[src]
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,