File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -381,6 +381,39 @@ impl fmt::Debug for ChildStderr {
381381///
382382/// let hello = output.stdout;
383383/// ```
384+ ///
385+ /// `Command` can be reused to spawn multiple processes. The builder methods
386+ /// change the command without needing to immediately spawn the process.
387+ ///
388+ /// ```no_run
389+ /// use std::process::Command;
390+ ///
391+ /// let mut echo_hello = Command::new("sh");
392+ /// echo_hello.arg("-c")
393+ /// .arg("echo hello");
394+ /// let hello_1 = echo_hello.output().expect("failed to execute process");
395+ /// let hello_2 = echo_hello.output().expect("failed to execute process");
396+ /// ```
397+ ///
398+ /// Similarly, you can call builder methods after spawning a process and then
399+ /// spawn a new process with the modified settings.
400+ ///
401+ /// ```no_run
402+ /// use std::process::Command;
403+ ///
404+ /// let mut list_dir = Command::new("ls");
405+ ///
406+ /// // Execute `ls` in the current directory of the program.
407+ /// list_dir.status().expect("process failed to execute");
408+ ///
409+ /// println!("");
410+ ///
411+ /// // Change `ls` to execute in the root directory.
412+ /// list_dir.current_dir("/");
413+ ///
414+ /// // And then execute `ls` again but in the root directory.
415+ /// list_dir.status().expect("process failed to execute");
416+ /// ```
384417#[ stable( feature = "process" , since = "1.0.0" ) ]
385418pub struct Command {
386419 inner : imp:: Command ,
You can’t perform that action at this time.
0 commit comments