|
10 | 10 |
|
11 | 11 | //! A module for working with processes.
|
12 | 12 | //!
|
13 |
| -//! This module provides a [`Command`] struct that can be used to configure and |
14 |
| -//! spawn a process, as well as a [`Child`] struct that represents a running or |
15 |
| -//! terminated process. |
| 13 | +//! This module is mostly concerned with spawning and interacting with child |
| 14 | +//! processes, but it also provides [`abort`] and [`exit`] for terminating the |
| 15 | +//! current process. |
16 | 16 | //!
|
17 |
| -//! # Examples |
| 17 | +//! # Spawning a process |
18 | 18 | //!
|
19 |
| -//! Hello world, `std::process` edition: |
| 19 | +//! The [`Command`] struct is used to configure and spawn processes: |
20 | 20 | //!
|
21 | 21 | //! ```
|
22 | 22 | //! use std::process::Command;
|
23 | 23 | //!
|
24 |
| -//! // Note that by default, the output of the command will be sent to stdout |
25 |
| -//! let mut child = Command::new("echo") |
26 |
| -//! .arg("Hello world") |
27 |
| -//! .spawn() |
28 |
| -//! .expect("Failed to start process"); |
29 |
| -//! |
30 |
| -//! let ecode = child.wait() |
31 |
| -//! .expect("Failed to wait on child"); |
| 24 | +//! let output = Command::new("echo") |
| 25 | +//! .arg("Hello world") |
| 26 | +//! .output() |
| 27 | +//! .expect("Failed to execute command"); |
32 | 28 | //!
|
33 |
| -//! assert!(ecode.success()); |
| 29 | +//! assert_eq!(b"Hello world\n", output.stdout.as_slice()); |
34 | 30 | //! ```
|
35 | 31 | //!
|
| 32 | +//! Several methods on [`Command`], such as [`spawn`] or [`output`], can be used |
| 33 | +//! to spawn a process. In particular, [`output`] spawns the child process and |
| 34 | +//! waits until the process terminates, while [`spawn`] will return a [`Child`] |
| 35 | +//! that represents the spawned child process. |
| 36 | +//! |
| 37 | +//! # Handling I/O |
| 38 | +//! |
| 39 | +//! TODO |
| 40 | +//! |
| 41 | +//! # Examples |
| 42 | +//! |
36 | 43 | //! Piping output from one command into another command:
|
37 | 44 | //!
|
38 | 45 | //! ```
|
|
86 | 93 | //! assert_eq!(b"test", output.stdout.as_slice());
|
87 | 94 | //! ```
|
88 | 95 | //!
|
| 96 | +//! [`abort`]: fn.abort.html |
| 97 | +//! [`exit`]: fn.exit.html |
| 98 | +//! |
89 | 99 | //! [`Command`]: struct.Command.html
|
| 100 | +//! [`spawn`]: struct.Command.html#method.spawn |
| 101 | +//! [`output`]: struct.Command.html#method.output |
| 102 | +//! |
90 | 103 | //! [`Child`]: struct.Child.html
|
| 104 | +//! [`Stdio`]: struct.Stdio.html |
91 | 105 |
|
92 | 106 | #![stable(feature = "process", since = "1.0.0")]
|
93 | 107 |
|
|
0 commit comments