From 53d308fdf86b7e499811650b89789c9c7161faab Mon Sep 17 00:00:00 2001 From: Ryan Scheel Date: Sat, 11 Aug 2018 03:13:29 -0700 Subject: [PATCH 1/2] Show that Command can be reused and remodified The prior documentation did not make it clear this was possible. --- src/libstd/process.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 39692836866b..ad64ed66e8ec 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -381,6 +381,39 @@ impl fmt::Debug for ChildStderr { /// /// let hello = output.stdout; /// ``` +/// +/// `Command` can be reused to spawn multiple processes. The builder methods +/// change the command without needing to immediately spawn the process. +/// +/// ```no_run +/// use std::process::Command; +/// +/// let mut echo_hello = Command::new("sh"); +/// echo_hello.arg("-c") +/// .arg("echo hello"); +/// let hello_1 = echo_hello.output().expect("failed to execute process"); +/// let hello_2 = echo_hello.output().expect("failed to execute process"); +/// ``` +/// +/// Similarly, you can call builder methods after spawning a process and then +/// spawn a new process with the modified settings. +/// +/// ```no_run +/// use std::process::Command; +/// +/// let mut list_dir = Command::new("ls"); +/// +/// // Execute `ls` in the current directory of the program. +/// list_dir.status().expect("process failed to execute"); +/// +/// println!(""); +/// +/// // Change `ls` to execute in the root directory. +/// list_dir.current_dir("/"); +/// +/// // And then execute `ls` again but in the root directory. +/// list_dir.status().expect("process failed to execute"); +/// ``` #[stable(feature = "process", since = "1.0.0")] pub struct Command { inner: imp::Command, From 0070b46626407f2e815993d46aef2b2637c2a4ed Mon Sep 17 00:00:00 2001 From: "Havvy (Ryan Scheel)" Date: Sat, 11 Aug 2018 13:02:49 -0700 Subject: [PATCH 2/2] Fix indent --- src/libstd/process.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index ad64ed66e8ec..53babd449a99 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -390,7 +390,7 @@ impl fmt::Debug for ChildStderr { /// /// let mut echo_hello = Command::new("sh"); /// echo_hello.arg("-c") -/// .arg("echo hello"); +/// .arg("echo hello"); /// let hello_1 = echo_hello.output().expect("failed to execute process"); /// let hello_2 = echo_hello.output().expect("failed to execute process"); /// ```