@@ -38,10 +38,10 @@ use sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
38
38
/// let mut child = Command::new("/bin/cat")
39
39
/// .arg("file.txt")
40
40
/// .spawn()
41
- /// .unwrap_or_else(|e| { panic!( "failed to execute child: {}", e) } );
41
+ /// .expect( "failed to execute child" );
42
42
///
43
43
/// let ecode = child.wait()
44
- /// .unwrap_or_else(|e| { panic!( "failed to wait on child: {}", e) } );
44
+ /// .expect( "failed to wait on child" );
45
45
///
46
46
/// assert!(ecode.success());
47
47
/// ```
@@ -195,7 +195,8 @@ impl FromInner<AnonPipe> for ChildStderr {
195
195
/// .arg("-c")
196
196
/// .arg("echo hello")
197
197
/// .output()
198
- /// .unwrap_or_else(|e| { panic!("failed to execute process: {}", e) });
198
+ /// .expect("failed to execute proces");
199
+ ///
199
200
/// let hello = output.stdout;
200
201
/// ```
201
202
#[ stable( feature = "process" , since = "1.0.0" ) ]
@@ -305,15 +306,16 @@ impl Command {
305
306
///
306
307
/// # Examples
307
308
///
308
- /// ```
309
+ /// ```should_panic
309
310
/// use std::process::Command;
310
- /// let output = Command::new("cat").arg("foo.txt").output().unwrap_or_else(|e| {
311
- /// panic!("failed to execute process: {}", e)
312
- /// });
311
+ /// let output = Command::new("/bin/cat").arg("file.txt").output()
312
+ /// .expect("failed to execute process");
313
313
///
314
314
/// println!("status: {}", output.status);
315
315
/// println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
316
316
/// println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
317
+ ///
318
+ /// assert!(output.status.success());
317
319
/// ```
318
320
#[ stable( feature = "process" , since = "1.0.0" ) ]
319
321
pub fn output ( & mut self ) -> io:: Result < Output > {
@@ -328,14 +330,15 @@ impl Command {
328
330
///
329
331
/// # Examples
330
332
///
331
- /// ```
333
+ /// ```should_panic
332
334
/// use std::process::Command;
333
335
///
334
- /// let status = Command::new("ls").status().unwrap_or_else(|e| {
335
- /// panic!("failed to execute process: {}", e)
336
- /// });
336
+ /// let status = Command::new("/bin/cat").arg("file.txt").status()
337
+ /// .expect("failed to execute process");
337
338
///
338
339
/// println!("process exited with: {}", status);
340
+ ///
341
+ /// assert!(status.success());
339
342
/// ```
340
343
#[ stable( feature = "process" , since = "1.0.0" ) ]
341
344
pub fn status ( & mut self ) -> io:: Result < ExitStatus > {
@@ -499,6 +502,29 @@ impl Child {
499
502
/// before waiting. This helps avoid deadlock: it ensures that the
500
503
/// child does not block waiting for input from the parent, while
501
504
/// the parent waits for the child to exit.
505
+ ///
506
+ /// By default, stdin, stdout and stderr are inherited from the parent.
507
+ /// In order to capture the output into this `Result<Output>` it is
508
+ /// necessary to create new pipes between parent and child. Use
509
+ /// `stdout(Stdio::piped())` or `stderr(Stdio::piped())`, respectively.
510
+ ///
511
+ /// # Examples
512
+ ///
513
+ /// ```should_panic
514
+ /// use std::process::{Command, Stdio};
515
+ ///
516
+ /// let mut child = Command::new("/bin/cat")
517
+ /// .arg("file.txt")
518
+ /// .stdout(Stdio::piped())
519
+ /// .spawn()
520
+ /// .expect("failed to execute child");
521
+ ///
522
+ /// let ecode = child.wait_with_output()
523
+ /// .expect("failed to wait on child");
524
+ ///
525
+ /// assert!(ecode.status.success());
526
+ /// ```
527
+ ///
502
528
#[ stable( feature = "process" , since = "1.0.0" ) ]
503
529
pub fn wait_with_output ( mut self ) -> io:: Result < Output > {
504
530
drop ( self . stdin . take ( ) ) ;
0 commit comments