Skip to content

Commit 8d61cb2

Browse files
committed
Extends rustdoc on how to caputure output
1 parent 2de6ddd commit 8d61cb2

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/libstd/process.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,29 @@ impl Child {
499499
/// before waiting. This helps avoid deadlock: it ensures that the
500500
/// child does not block waiting for input from the parent, while
501501
/// the parent waits for the child to exit.
502+
///
503+
/// By default, stdin, stdout and stderr are inherited from the parent.
504+
/// In order to capture the output into this `Result<Output>` it is
505+
/// necessary to create new pipes between parent and child. Use
506+
/// `stdout(Stdio::piped())` or `stdout(Stdio::piped())`, respectively.
507+
///
508+
/// # Examples
509+
///
510+
/// ```should_panic
511+
/// use std::process::{Command, Stdio};
512+
///
513+
/// let mut child = Command::new("/bin/cat")
514+
/// .stdout(Stdio::piped())
515+
/// .arg("file.txt")
516+
/// .spawn()
517+
/// .unwrap_or_else(|e| { panic!("failed to execute child: {}", e) });
518+
///
519+
/// let ecode = child.wait_with_output()
520+
/// .unwrap_or_else(|e| { panic!("failed to wait on child: {}", e) });
521+
///
522+
/// assert!(ecode.success());
523+
/// ```
524+
///
502525
#[stable(feature = "process", since = "1.0.0")]
503526
pub fn wait_with_output(mut self) -> io::Result<Output> {
504527
drop(self.stdin.take());

0 commit comments

Comments
 (0)