Skip to content

Commit

Permalink
Clarify Command::new behavior if passed programs with arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jieyouxu committed Jun 9, 2024
1 parent b3ca6ee commit 7ad167d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,26 @@ impl Command {
/// .spawn()
/// .expect("sh command failed to start");
/// ```
///
/// # Caveats
///
/// [`Command::new`] is only intended to accept the path of the program. If you pass a program
/// path along with arguments such as `ls -l` for the program `ls` and argument `-l`, it will
/// try to search for `ls -l` literally.
///
/// ```no_run (example demonstrating incorrect usage)
/// use std::process::Command;
///
/// // Does not launch `ls`, will try to launch a program named `ls -l` literally.
/// Command::new("ls -l")
/// .spawn()
/// .unwrap();
/// ```
///
/// The arguments need to be passed separately, such as via [`arg`] or [`args`].
///
/// [`arg`]: Self::arg
/// [`args`]: Self::args
#[stable(feature = "process", since = "1.0.0")]
pub fn new<S: AsRef<OsStr>>(program: S) -> Command {
Command { inner: imp::Command::new(program.as_ref()) }
Expand Down

0 comments on commit 7ad167d

Please sign in to comment.