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 10, 2024
1 parent 06194ca commit 9844d7f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,16 @@ 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 like `Command::new("ls -l").spawn()`, it will try to search for
/// `ls -l` literally. 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 9844d7f

Please sign in to comment.