Skip to content

Commit f67f662

Browse files
committed
Create section on how to spawn processes; change module description
1 parent bb74b13 commit f67f662

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

src/libstd/process.rs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,36 @@
1010

1111
//! A module for working with processes.
1212
//!
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.
1616
//!
17-
//! # Examples
17+
//! # Spawning a process
1818
//!
19-
//! Hello world, `std::process` edition:
19+
//! The [`Command`] struct is used to configure and spawn processes:
2020
//!
2121
//! ```
2222
//! use std::process::Command;
2323
//!
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");
3228
//!
33-
//! assert!(ecode.success());
29+
//! assert_eq!(b"Hello world\n", output.stdout.as_slice());
3430
//! ```
3531
//!
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+
//!
3643
//! Piping output from one command into another command:
3744
//!
3845
//! ```
@@ -86,8 +93,15 @@
8693
//! assert_eq!(b"test", output.stdout.as_slice());
8794
//! ```
8895
//!
96+
//! [`abort`]: fn.abort.html
97+
//! [`exit`]: fn.exit.html
98+
//!
8999
//! [`Command`]: struct.Command.html
100+
//! [`spawn`]: struct.Command.html#method.spawn
101+
//! [`output`]: struct.Command.html#method.output
102+
//!
90103
//! [`Child`]: struct.Child.html
104+
//! [`Stdio`]: struct.Stdio.html
91105
92106
#![stable(feature = "process", since = "1.0.0")]
93107

0 commit comments

Comments
 (0)