about summary refs log tree commit diff
path: root/src/libstd/process.rs
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2018-08-12 23:27:01 +0200
committerGitHub <noreply@github.com>2018-08-12 23:27:01 +0200
commit17d4bd0c0beb6619bb60d76e088321a897ff8128 (patch)
treec8b0b171cf9ffd6bda15a0b1062899a6d0fbaa2f /src/libstd/process.rs
parentb0d7f91c4e15b8d5da71d4dd32917973c130af19 (diff)
parent0070b46626407f2e815993d46aef2b2637c2a4ed (diff)
downloadrust-17d4bd0c0beb6619bb60d76e088321a897ff8128.tar.gz
rust-17d4bd0c0beb6619bb60d76e088321a897ff8128.zip
Rollup merge of #53264 - Havvy:patch-3, r=GuillaumeGomez
Show that Command can be reused and remodified

The prior documentation did not make it clear this was possible.

I wanted to make the `list_dir` example work on Windows, but I don't know if passing "/" will error or show the root of the current volume (e.g. `C:`).

r? @GuillaumeGomez
Diffstat (limited to 'src/libstd/process.rs')
-rw-r--r--src/libstd/process.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/libstd/process.rs b/src/libstd/process.rs
index 39692836866..53babd449a9 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,