From 7717d22349b8d3b3b44af476ccf4e7171867db24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Wed, 10 Apr 2024 14:17:16 +0000 Subject: [PATCH] std/process/command: clarify Command::new behavior for programs with arguments --- library/std/src/process.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 69cc61b30efe9..a1d52c1ba79e5 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -606,6 +606,22 @@ impl Command { /// but this has some implementation limitations on Windows /// (see issue #37519). /// + /// [`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 [`Command::arg`] or + /// [`Command::args`]. + /// /// # Platform-specific behavior /// /// Note on Windows: For executable files with the .exe extension,