about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAleksandr Kovalev <aleksandr@kovalev.engineer>2023-07-17 14:22:01 +0200
committerAleksandr Kovalev <aleksandr@kovalev.engineer>2023-07-18 11:32:04 +0200
commit5dea766dc98d05b4a3a933eb0998a5686d48cc76 (patch)
tree46bdec6de45333a199c20ef774ebcc4d48c789bb
parent6f65ef57177ce0095171f70d0b010567c35e68cc (diff)
Update documentation for std::process::Command's new method
In the current documentation, it's not specified that when creating
a Command, the .exe extension can be omitted for Windows executables.
However, for other types of executable files like .bat or .cmd,
the complete filename including the extension must be provided.

I encountered it by noticing that `Command::new("wt").spawn().unwrap()`
succeeds on my machine while `Command::new("code").spawn().unwrap()`
panics. Turns out VS Code's entrypoint is .cmd file.

`resolve_exe` method mentions this behaviour in a comment[1], but it
makes sense to mention it at more visible place.

I've added this clarification to the documentation, which should
make it more accurate and helpful for Rust developers
working on the Windows platform.

[1] https://github.com/rust-lang/rust/blob/e7fda447e7d05b6ca431fc8fe8f489b1fda810bc/library/std/src/sys/windows/process.rs#L425
-rw-r--r--library/std/src/process.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/library/std/src/process.rs b/library/std/src/process.rs
index 8f3201b0091..f9cb755b01a 100644
--- a/library/std/src/process.rs
+++ b/library/std/src/process.rs
@@ -558,6 +558,14 @@ impl Command {
     /// but this has some implementation limitations on Windows
     /// (see issue #37519).
     ///
+    /// # Platform-specific behavior
+    ///
+    /// Note on Windows: For executable files with the .exe extension,
+    /// it can be omitted when specifying the program for this Command.
+    /// However, if the file has a different extension,
+    /// a filename including the extension needs to be provided,
+    /// otherwise the file won't be found.
+    ///
     /// # Examples
     ///
     /// Basic usage: