@@ -525,9 +525,11 @@ impl Command {
525
525
/// ```no_run
526
526
/// use std::process::Command;
527
527
///
528
- /// Command::new("sh")
529
- /// .spawn ()
528
+ /// let status = Command::new("sh")
529
+ /// .status ()
530
530
/// .expect("sh command failed to start");
531
+ ///
532
+ /// assert!(status.success());
531
533
/// ```
532
534
#[ stable( feature = "process" , since = "1.0.0" ) ]
533
535
pub fn new < S : AsRef < OsStr > > ( program : S ) -> Command {
@@ -569,11 +571,13 @@ impl Command {
569
571
/// ```no_run
570
572
/// use std::process::Command;
571
573
///
572
- /// Command::new("ls")
574
+ /// let status = Command::new("ls")
573
575
/// .arg("-l")
574
576
/// .arg("-a")
575
- /// .spawn ()
577
+ /// .status ()
576
578
/// .expect("ls command failed to start");
579
+ ///
580
+ /// assert!(status.success());
577
581
/// ```
578
582
#[ stable( feature = "process" , since = "1.0.0" ) ]
579
583
pub fn arg < S : AsRef < OsStr > > ( & mut self , arg : S ) -> & mut Command {
@@ -599,10 +603,12 @@ impl Command {
599
603
/// ```no_run
600
604
/// use std::process::Command;
601
605
///
602
- /// Command::new("ls")
606
+ /// let status = Command::new("ls")
603
607
/// .args(&["-l", "-a"])
604
- /// .spawn ()
608
+ /// .status ()
605
609
/// .expect("ls command failed to start");
610
+ ///
611
+ /// assert!(status.success());
606
612
/// ```
607
613
#[ stable( feature = "process" , since = "1.0.0" ) ]
608
614
pub fn args < I , S > ( & mut self , args : I ) -> & mut Command
@@ -628,10 +634,12 @@ impl Command {
628
634
/// ```no_run
629
635
/// use std::process::Command;
630
636
///
631
- /// Command::new("ls")
637
+ /// let status = Command::new("ls")
632
638
/// .env("PATH", "/bin")
633
- /// .spawn ()
639
+ /// .status ()
634
640
/// .expect("ls command failed to start");
641
+ ///
642
+ /// assert!(status.success());
635
643
/// ```
636
644
#[ stable( feature = "process" , since = "1.0.0" ) ]
637
645
pub fn env < K , V > ( & mut self , key : K , val : V ) -> & mut Command
@@ -659,13 +667,15 @@ impl Command {
659
667
/// k == "TERM" || k == "TZ" || k == "LANG" || k == "PATH"
660
668
/// ).collect();
661
669
///
662
- /// Command::new("printenv")
670
+ /// let status = Command::new("printenv")
663
671
/// .stdin(Stdio::null())
664
672
/// .stdout(Stdio::inherit())
665
673
/// .env_clear()
666
674
/// .envs(&filtered_env)
667
- /// .spawn ()
675
+ /// .status ()
668
676
/// .expect("printenv failed to start");
677
+ ///
678
+ /// assert!(status.success());
669
679
/// ```
670
680
#[ stable( feature = "command_envs" , since = "1.19.0" ) ]
671
681
pub fn envs < I , K , V > ( & mut self , vars : I ) -> & mut Command
@@ -689,10 +699,12 @@ impl Command {
689
699
/// ```no_run
690
700
/// use std::process::Command;
691
701
///
692
- /// Command::new("ls")
702
+ /// let status = Command::new("ls")
693
703
/// .env_remove("PATH")
694
- /// .spawn ()
704
+ /// .status ()
695
705
/// .expect("ls command failed to start");
706
+ ///
707
+ /// assert!(status.success());
696
708
/// ```
697
709
#[ stable( feature = "process" , since = "1.0.0" ) ]
698
710
pub fn env_remove < K : AsRef < OsStr > > ( & mut self , key : K ) -> & mut Command {
@@ -709,10 +721,12 @@ impl Command {
709
721
/// ```no_run
710
722
/// use std::process::Command;
711
723
///
712
- /// Command::new("ls")
724
+ /// let status = Command::new("ls")
713
725
/// .env_clear()
714
- /// .spawn ()
726
+ /// .status ()
715
727
/// .expect("ls command failed to start");
728
+ ///
729
+ /// assert!(status.success());
716
730
/// ```
717
731
#[ stable( feature = "process" , since = "1.0.0" ) ]
718
732
pub fn env_clear ( & mut self ) -> & mut Command {
@@ -737,10 +751,12 @@ impl Command {
737
751
/// ```no_run
738
752
/// use std::process::Command;
739
753
///
740
- /// Command::new("ls")
754
+ /// let status = Command::new("ls")
741
755
/// .current_dir("/bin")
742
- /// .spawn ()
756
+ /// .status ()
743
757
/// .expect("ls command failed to start");
758
+ ///
759
+ /// assert!(status.success());
744
760
/// ```
745
761
///
746
762
/// [`canonicalize`]: crate::fs::canonicalize
@@ -765,10 +781,12 @@ impl Command {
765
781
/// ```no_run
766
782
/// use std::process::{Command, Stdio};
767
783
///
768
- /// Command::new("ls")
784
+ /// let status = Command::new("ls")
769
785
/// .stdin(Stdio::null())
770
- /// .spawn ()
786
+ /// .status ()
771
787
/// .expect("ls command failed to start");
788
+ ///
789
+ /// assert!(status.success());
772
790
/// ```
773
791
#[ stable( feature = "process" , since = "1.0.0" ) ]
774
792
pub fn stdin < T : Into < Stdio > > ( & mut self , cfg : T ) -> & mut Command {
@@ -791,10 +809,12 @@ impl Command {
791
809
/// ```no_run
792
810
/// use std::process::{Command, Stdio};
793
811
///
794
- /// Command::new("ls")
812
+ /// let status = Command::new("ls")
795
813
/// .stdout(Stdio::null())
796
- /// .spawn ()
814
+ /// .status ()
797
815
/// .expect("ls command failed to start");
816
+ ///
817
+ /// assert!(status.success());
798
818
/// ```
799
819
#[ stable( feature = "process" , since = "1.0.0" ) ]
800
820
pub fn stdout < T : Into < Stdio > > ( & mut self , cfg : T ) -> & mut Command {
@@ -817,10 +837,12 @@ impl Command {
817
837
/// ```no_run
818
838
/// use std::process::{Command, Stdio};
819
839
///
820
- /// Command::new("ls")
840
+ /// let status = Command::new("ls")
821
841
/// .stderr(Stdio::null())
822
- /// .spawn ()
842
+ /// .status ()
823
843
/// .expect("ls command failed to start");
844
+ ///
845
+ /// assert!(status.success());
824
846
/// ```
825
847
#[ stable( feature = "process" , since = "1.0.0" ) ]
826
848
pub fn stderr < T : Into < Stdio > > ( & mut self , cfg : T ) -> & mut Command {
0 commit comments