Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7717d22

Browse files
committedApr 10, 2024
std/process/command: clarify Command::new behavior for programs with arguments
1 parent b14d8b2 commit 7717d22

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
 

‎library/std/src/process.rs

+16
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,22 @@ impl Command {
606606
/// but this has some implementation limitations on Windows
607607
/// (see issue #37519).
608608
///
609+
/// [`Command::new`] is only intended to accept the path of the program. If you pass a program
610+
/// path along with arguments such as `ls -l` for the program `ls` and argument `-l`, it will
611+
/// try to search for `ls -l` literally.
612+
///
613+
/// ```no_run (example demonstrating incorrect usage)
614+
/// use std::process::Command;
615+
///
616+
/// // Does not launch `ls`, will try to launch a program named `ls -l` literally.
617+
/// Command::new("ls -l")
618+
/// .spawn()
619+
/// .unwrap();
620+
/// ```
621+
///
622+
/// The arguments need to be passed separately, such as via [`Command::arg`] or
623+
/// [`Command::args`].
624+
///
609625
/// # Platform-specific behavior
610626
///
611627
/// Note on Windows: For executable files with the .exe extension,

0 commit comments

Comments
 (0)
Failed to load comments.