Description
Feature gate: #![feature(windows_process_extensions_raw_arg)]
This is a tracking issue for the raw_arg extension to std::process::Command
on Windows.
Windows programs on the lowest API layers actually aren't required to accept arguments as an array of strings.
In fact the illusion that they do accept arguments as an array of strings is mostly maintained by one function. CommandLineToArgvW. Not all programs use that function to parse arguments. Some of the programs that don't do this are really important, like cmd.exe
. These programs instead read their argument as one large string, which makes them incompatible with how std::process::Command::arg
passes the arguments. std::process::Command::arg
assumes the program will parse the string using CommandLineToArgvW
. Most of the time this is a reasonable assumption to make.
Solution: raw_arg
. Strings passed via raw_arg
are sent straight through with no alteration, save for inserting spaces inbetween them. Raw args are not quoted, escaped, or really anything complicated like that. This makes them compatible with Windows executable files which don't use CommandLineToArgvW.
Public API
use std::process::Command;
// This will print
// "Hello World!"
// with the quotes, which is not possible with std::process::Command and `cmd.exe`
// with the current `.arg()` method.
let cmd = Command::new("cmd.exe").raw_arg("/C echo \"Hello World!\"");
// You can also chain this
Command::new("cmd.exe")
.raw_arg("/C")
.raw_arg("echo")
.raw_arg("\"Hello World!\"")
Steps / History
- Implementation: Unescaped command-line arguments for Windows #85832
- Final comment period (FCP)
- Stabilization PR stabilize windows_process_extensions_raw_arg #92942
Unresolved Questions
- None yet.