12
12
//! use std::process::Command;
13
13
//!
14
14
//! let output = Command::new("echo")
15
- //! .arg("Hello world")
16
- //! .output()
17
- //! .expect("Failed to execute command");
15
+ //! .arg("Hello world")
16
+ //! .output()
17
+ //! .expect("Failed to execute command");
18
18
//!
19
19
//! assert_eq!(b"Hello world\n", output.stdout.as_slice());
20
20
//! ```
@@ -154,12 +154,11 @@ use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
154
154
/// use std::process::Command;
155
155
///
156
156
/// let mut child = Command::new("/bin/cat")
157
- /// .arg("file.txt")
158
- /// .spawn()
159
- /// .expect("failed to execute child");
157
+ /// .arg("file.txt")
158
+ /// .spawn()
159
+ /// .expect("failed to execute child");
160
160
///
161
- /// let ecode = child.wait()
162
- /// .expect("failed to wait on child");
161
+ /// let ecode = child.wait().expect("failed to wait on child");
163
162
///
164
163
/// assert!(ecode.success());
165
164
/// ```
@@ -481,15 +480,15 @@ impl fmt::Debug for ChildStderr {
481
480
///
482
481
/// let output = if cfg!(target_os = "windows") {
483
482
/// Command::new("cmd")
484
- /// .args(["/C", "echo hello"])
485
- /// .output()
486
- /// .expect("failed to execute process")
483
+ /// .args(["/C", "echo hello"])
484
+ /// .output()
485
+ /// .expect("failed to execute process")
487
486
/// } else {
488
487
/// Command::new("sh")
489
- /// .arg("-c")
490
- /// .arg("echo hello")
491
- /// .output()
492
- /// .expect("failed to execute process")
488
+ /// .arg("-c")
489
+ /// .arg("echo hello")
490
+ /// .output()
491
+ /// .expect("failed to execute process")
493
492
/// };
494
493
///
495
494
/// let hello = output.stdout;
@@ -502,8 +501,7 @@ impl fmt::Debug for ChildStderr {
502
501
/// use std::process::Command;
503
502
///
504
503
/// let mut echo_hello = Command::new("sh");
505
- /// echo_hello.arg("-c")
506
- /// .arg("echo hello");
504
+ /// echo_hello.arg("-c").arg("echo hello");
507
505
/// let hello_1 = echo_hello.output().expect("failed to execute process");
508
506
/// let hello_2 = echo_hello.output().expect("failed to execute process");
509
507
/// ```
@@ -576,8 +574,8 @@ impl Command {
576
574
/// use std::process::Command;
577
575
///
578
576
/// Command::new("sh")
579
- /// .spawn()
580
- /// .expect("sh command failed to start");
577
+ /// .spawn()
578
+ /// .expect("sh command failed to start");
581
579
/// ```
582
580
#[ stable( feature = "process" , since = "1.0.0" ) ]
583
581
pub fn new < S : AsRef < OsStr > > ( program : S ) -> Command {
@@ -620,10 +618,10 @@ impl Command {
620
618
/// use std::process::Command;
621
619
///
622
620
/// Command::new("ls")
623
- /// .arg("-l")
624
- /// .arg("-a")
625
- /// .spawn()
626
- /// .expect("ls command failed to start");
621
+ /// .arg("-l")
622
+ /// .arg("-a")
623
+ /// .spawn()
624
+ /// .expect("ls command failed to start");
627
625
/// ```
628
626
#[ stable( feature = "process" , since = "1.0.0" ) ]
629
627
pub fn arg < S : AsRef < OsStr > > ( & mut self , arg : S ) -> & mut Command {
@@ -650,9 +648,9 @@ impl Command {
650
648
/// use std::process::Command;
651
649
///
652
650
/// Command::new("ls")
653
- /// .args(["-l", "-a"])
654
- /// .spawn()
655
- /// .expect("ls command failed to start");
651
+ /// .args(["-l", "-a"])
652
+ /// .spawn()
653
+ /// .expect("ls command failed to start");
656
654
/// ```
657
655
#[ stable( feature = "process" , since = "1.0.0" ) ]
658
656
pub fn args < I , S > ( & mut self , args : I ) -> & mut Command
@@ -688,9 +686,9 @@ impl Command {
688
686
/// use std::process::Command;
689
687
///
690
688
/// Command::new("ls")
691
- /// .env("PATH", "/bin")
692
- /// .spawn()
693
- /// .expect("ls command failed to start");
689
+ /// .env("PATH", "/bin")
690
+ /// .spawn()
691
+ /// .expect("ls command failed to start");
694
692
/// ```
695
693
#[ stable( feature = "process" , since = "1.0.0" ) ]
696
694
pub fn env < K , V > ( & mut self , key : K , val : V ) -> & mut Command
@@ -731,12 +729,12 @@ impl Command {
731
729
/// ).collect();
732
730
///
733
731
/// Command::new("printenv")
734
- /// .stdin(Stdio::null())
735
- /// .stdout(Stdio::inherit())
736
- /// .env_clear()
737
- /// .envs(&filtered_env)
738
- /// .spawn()
739
- /// .expect("printenv failed to start");
732
+ /// .stdin(Stdio::null())
733
+ /// .stdout(Stdio::inherit())
734
+ /// .env_clear()
735
+ /// .envs(&filtered_env)
736
+ /// .spawn()
737
+ /// .expect("printenv failed to start");
740
738
/// ```
741
739
#[ stable( feature = "command_envs" , since = "1.19.0" ) ]
742
740
pub fn envs < I , K , V > ( & mut self , vars : I ) -> & mut Command
@@ -772,9 +770,9 @@ impl Command {
772
770
/// use std::process::Command;
773
771
///
774
772
/// Command::new("ls")
775
- /// .env_remove("PATH")
776
- /// .spawn()
777
- /// .expect("ls command failed to start");
773
+ /// .env_remove("PATH")
774
+ /// .spawn()
775
+ /// .expect("ls command failed to start");
778
776
/// ```
779
777
#[ stable( feature = "process" , since = "1.0.0" ) ]
780
778
pub fn env_remove < K : AsRef < OsStr > > ( & mut self , key : K ) -> & mut Command {
@@ -802,9 +800,9 @@ impl Command {
802
800
/// use std::process::Command;
803
801
///
804
802
/// Command::new("ls")
805
- /// .env_clear()
806
- /// .spawn()
807
- /// .expect("ls command failed to start");
803
+ /// .env_clear()
804
+ /// .spawn()
805
+ /// .expect("ls command failed to start");
808
806
/// ```
809
807
#[ stable( feature = "process" , since = "1.0.0" ) ]
810
808
pub fn env_clear ( & mut self ) -> & mut Command {
@@ -830,9 +828,9 @@ impl Command {
830
828
/// use std::process::Command;
831
829
///
832
830
/// Command::new("ls")
833
- /// .current_dir("/bin")
834
- /// .spawn()
835
- /// .expect("ls command failed to start");
831
+ /// .current_dir("/bin")
832
+ /// .spawn()
833
+ /// .expect("ls command failed to start");
836
834
/// ```
837
835
///
838
836
/// [`canonicalize`]: crate::fs::canonicalize
@@ -861,9 +859,9 @@ impl Command {
861
859
/// use std::process::{Command, Stdio};
862
860
///
863
861
/// Command::new("ls")
864
- /// .stdin(Stdio::null())
865
- /// .spawn()
866
- /// .expect("ls command failed to start");
862
+ /// .stdin(Stdio::null())
863
+ /// .spawn()
864
+ /// .expect("ls command failed to start");
867
865
/// ```
868
866
#[ stable( feature = "process" , since = "1.0.0" ) ]
869
867
pub fn stdin < T : Into < Stdio > > ( & mut self , cfg : T ) -> & mut Command {
@@ -890,9 +888,9 @@ impl Command {
890
888
/// use std::process::{Command, Stdio};
891
889
///
892
890
/// Command::new("ls")
893
- /// .stdout(Stdio::null())
894
- /// .spawn()
895
- /// .expect("ls command failed to start");
891
+ /// .stdout(Stdio::null())
892
+ /// .spawn()
893
+ /// .expect("ls command failed to start");
896
894
/// ```
897
895
#[ stable( feature = "process" , since = "1.0.0" ) ]
898
896
pub fn stdout < T : Into < Stdio > > ( & mut self , cfg : T ) -> & mut Command {
@@ -919,9 +917,9 @@ impl Command {
919
917
/// use std::process::{Command, Stdio};
920
918
///
921
919
/// Command::new("ls")
922
- /// .stderr(Stdio::null())
923
- /// .spawn()
924
- /// .expect("ls command failed to start");
920
+ /// .stderr(Stdio::null())
921
+ /// .spawn()
922
+ /// .expect("ls command failed to start");
925
923
/// ```
926
924
#[ stable( feature = "process" , since = "1.0.0" ) ]
927
925
pub fn stderr < T : Into < Stdio > > ( & mut self , cfg : T ) -> & mut Command {
@@ -941,8 +939,8 @@ impl Command {
941
939
/// use std::process::Command;
942
940
///
943
941
/// Command::new("ls")
944
- /// .spawn()
945
- /// .expect("ls command failed to start");
942
+ /// .spawn()
943
+ /// .expect("ls command failed to start");
946
944
/// ```
947
945
#[ stable( feature = "process" , since = "1.0.0" ) ]
948
946
pub fn spawn ( & mut self ) -> io:: Result < Child > {
@@ -963,9 +961,9 @@ impl Command {
963
961
/// use std::process::Command;
964
962
/// use std::io::{self, Write};
965
963
/// let output = Command::new("/bin/cat")
966
- /// .arg("file.txt")
967
- /// .output()
968
- /// .expect("failed to execute process");
964
+ /// .arg("file.txt")
965
+ /// .output()
966
+ /// .expect("failed to execute process");
969
967
///
970
968
/// println!("status: {}", output.status);
971
969
/// io::stdout().write_all(&output.stdout).unwrap();
@@ -990,9 +988,9 @@ impl Command {
990
988
/// use std::process::Command;
991
989
///
992
990
/// let status = Command::new("/bin/cat")
993
- /// .arg("file.txt")
994
- /// .status()
995
- /// .expect("failed to execute process");
991
+ /// .arg("file.txt")
992
+ /// .status()
993
+ /// .expect("failed to execute process");
996
994
///
997
995
/// println!("process finished with: {status}");
998
996
///
@@ -1618,9 +1616,9 @@ impl ExitStatus {
1618
1616
/// use std::process::Command;
1619
1617
///
1620
1618
/// let status = Command::new("ls")
1621
- /// .arg("/dev/nonexistent")
1622
- /// .status()
1623
- /// .expect("ls could not be executed");
1619
+ /// .arg("/dev/nonexistent")
1620
+ /// .status()
1621
+ /// .expect("ls could not be executed");
1624
1622
///
1625
1623
/// println!("ls: {status}");
1626
1624
/// status.exit_ok().expect_err("/dev/nonexistent could be listed!");
@@ -1640,9 +1638,9 @@ impl ExitStatus {
1640
1638
/// use std::process::Command;
1641
1639
///
1642
1640
/// let status = Command::new("mkdir")
1643
- /// .arg("projects")
1644
- /// .status()
1645
- /// .expect("failed to execute mkdir");
1641
+ /// .arg("projects")
1642
+ /// .status()
1643
+ /// .expect("failed to execute mkdir");
1646
1644
///
1647
1645
/// if status.success() {
1648
1646
/// println!("'projects/' directory created");
@@ -1673,13 +1671,13 @@ impl ExitStatus {
1673
1671
/// use std::process::Command;
1674
1672
///
1675
1673
/// let status = Command::new("mkdir")
1676
- /// .arg("projects")
1677
- /// .status()
1678
- /// .expect("failed to execute mkdir");
1674
+ /// .arg("projects")
1675
+ /// .status()
1676
+ /// .expect("failed to execute mkdir");
1679
1677
///
1680
1678
/// match status.code() {
1681
1679
/// Some(code) => println!("Exited with status code: {code}"),
1682
- /// None => println!("Process terminated by signal")
1680
+ /// None => println!("Process terminated by signal")
1683
1681
/// }
1684
1682
/// ```
1685
1683
#[ must_use]
0 commit comments