about summary refs log tree commit diff
path: root/library/std/src/process.rs
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <jieyouxu@outlook.com>2024-04-10 14:17:16 +0000
committer许杰友 Jieyou Xu (Joe) <jieyouxu@outlook.com>2024-06-10 12:25:05 +0000
commitbd6fca201551382e12f08de37c1f67bc3deb968d (patch)
treebea81a5f797d798bf26e3edc5a82ff4adcbf4031 /library/std/src/process.rs
parent06194cadcd0948a7100b46737f61e82b8c00d632 (diff)
downloadrust-bd6fca201551382e12f08de37c1f67bc3deb968d.tar.gz
rust-bd6fca201551382e12f08de37c1f67bc3deb968d.zip
Clarify `Command::new` behavior if passed programs with arguments
Diffstat (limited to 'library/std/src/process.rs')
-rw-r--r--library/std/src/process.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/library/std/src/process.rs b/library/std/src/process.rs
index c926c89f7a9..f351dab78dc 100644
--- a/library/std/src/process.rs
+++ b/library/std/src/process.rs
@@ -629,6 +629,25 @@ 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`].
+    ///
+    /// ```no_run
+    /// use std::process::Command;
+    ///
+    /// Command::new("ls")
+    ///     .arg("-l") // arg passed separately
+    ///     .spawn()
+    ///     .expect("ls command failed to start");
+    /// ```
+    ///
+    /// [`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()) }