-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Improve std::process module docs #45295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
5243a98
e788e90
bb74b13
f67f662
3566832
84ab6ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,22 +10,62 @@ | |
|
||
//! A module for working with processes. | ||
//! | ||
//! # Examples | ||
//! This module is mostly concerned with spawning and interacting with child | ||
//! processes, but it also provides [`abort`] and [`exit`] for terminating the | ||
//! current process. | ||
//! | ||
//! # Spawning a process | ||
//! | ||
//! Basic usage where we try to execute the `cat` shell command: | ||
//! The [`Command`] struct is used to configure and spawn processes: | ||
//! | ||
//! ```should_panic | ||
//! ``` | ||
//! use std::process::Command; | ||
//! | ||
//! let mut child = Command::new("/bin/cat") | ||
//! .arg("file.txt") | ||
//! .spawn() | ||
//! .expect("failed to execute child"); | ||
//! let output = Command::new("echo") | ||
//! .arg("Hello world") | ||
//! .output() | ||
//! .expect("Failed to execute command"); | ||
//! | ||
//! assert_eq!(b"Hello world\n", output.stdout.as_slice()); | ||
//! ``` | ||
//! | ||
//! Several methods on [`Command`], such as [`spawn`] or [`output`], can be used | ||
//! to spawn a process. In particular, [`output`] spawns the child process and | ||
//! waits until the process terminates, while [`spawn`] will return a [`Child`] | ||
//! that represents the spawned child process. | ||
//! | ||
//! # Handling I/O | ||
//! | ||
//! TODO | ||
//! | ||
//! # Examples | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this moved down? The above is still an example 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! I planned on having a brief overview of the entire module first and then show some additional examples. Maybe I should rename the "Example" section to "Additional Examples"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just figured out that I could just fold the examples into the section describing |
||
//! | ||
//! Piping output from one command into another command: | ||
//! | ||
//! let ecode = child.wait() | ||
//! .expect("failed to wait on child"); | ||
//! ``` | ||
//! use std::process::{Command, Stdio}; | ||
//! | ||
//! // stdout must be configured with `Stdio::piped` in order to use | ||
//! // `echo_child.stdout` | ||
//! let echo_child = Command::new("echo") | ||
//! .arg("Oh no, a tpyo!") | ||
//! .stdout(Stdio::piped()) | ||
//! .spawn() | ||
//! .expect("Failed to start echo process"); | ||
//! | ||
//! // Note that `echo_child` is moved here, but we won't be needing | ||
//! // `echo_child` anymore | ||
//! let echo_out = echo_child.stdout.expect("Failed to open echo stdout"); | ||
//! | ||
//! assert!(ecode.success()); | ||
//! let mut sed_child = Command::new("sed") | ||
//! .arg("s/tpyo/typo/") | ||
//! .stdin(Stdio::from(echo_out)) | ||
//! .stdout(Stdio::piped()) | ||
//! .spawn() | ||
//! .expect("Failed to start sed process"); | ||
//! | ||
//! let output = sed_child.wait_with_output().expect("Failed to wait on sed"); | ||
//! assert_eq!(b"Oh no, a typo!\n", output.stdout.as_slice()); | ||
//! ``` | ||
//! | ||
//! Calling a command with input and reading its output: | ||
|
@@ -52,6 +92,16 @@ | |
//! | ||
//! assert_eq!(b"test", output.stdout.as_slice()); | ||
//! ``` | ||
//! | ||
//! [`abort`]: fn.abort.html | ||
//! [`exit`]: fn.exit.html | ||
//! | ||
//! [`Command`]: struct.Command.html | ||
//! [`spawn`]: struct.Command.html#method.spawn | ||
//! [`output`]: struct.Command.html#method.output | ||
//! | ||
//! [`Child`]: struct.Child.html | ||
//! [`Stdio`]: struct.Stdio.html | ||
|
||
#![stable(feature = "process", since = "1.0.0")] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you intend on filling this out in this PR? If not, I'd remove this section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I plan on adding a few demonstrations of
Stdio
here. Incidentally, theTODO
is causing travis to fail.