Skip to content

Commit 7ad167d

Browse files
committed
Clarify Command::new behavior if passed programs with arguments
1 parent b3ca6ee commit 7ad167d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

library/std/src/process.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,26 @@ impl Command {
629629
/// .spawn()
630630
/// .expect("sh command failed to start");
631631
/// ```
632+
///
633+
/// # Caveats
634+
///
635+
/// [`Command::new`] is only intended to accept the path of the program. If you pass a program
636+
/// path along with arguments such as `ls -l` for the program `ls` and argument `-l`, it will
637+
/// try to search for `ls -l` literally.
638+
///
639+
/// ```no_run (example demonstrating incorrect usage)
640+
/// use std::process::Command;
641+
///
642+
/// // Does not launch `ls`, will try to launch a program named `ls -l` literally.
643+
/// Command::new("ls -l")
644+
/// .spawn()
645+
/// .unwrap();
646+
/// ```
647+
///
648+
/// The arguments need to be passed separately, such as via [`arg`] or [`args`].
649+
///
650+
/// [`arg`]: Self::arg
651+
/// [`args`]: Self::args
632652
#[stable(feature = "process", since = "1.0.0")]
633653
pub fn new<S: AsRef<OsStr>>(program: S) -> Command {
634654
Command { inner: imp::Command::new(program.as_ref()) }

0 commit comments

Comments
 (0)