-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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 #85832Final comment period (FCP)Stabilization PR stabilize windows_process_extensions_raw_arg #92942To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Unresolved Questions
- None yet.
Activity
Xaeroxe commentedon Jan 15, 2022
I need a Rust team member to kick off an FCP for this.
m-ou-se commentedon Mar 9, 2022
@rfcbot merge
rfcbot commentedon Mar 9, 2022
Team member @m-ou-se has proposed to merge this. The next step is review by the rest of the tagged team members:
No concerns currently listed.
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
See this document for info about what commands tagged team members can give me.
nico commentedon Mar 25, 2022
If I have a string containing a full command (e.g.
myprogram.exe myArg1 myArg2
), how would I use this new API to create a process running that command?I want to have something that behaves as if I passed that string to
CreateProcessA()
.Running
Command::new("cmd.exe").raw_arg("/C").raw_arg(mystring)
isn't an option, since as soon as you bring cmd.exe into play, your subject to its commandline limit of 8192 characters.Having to split off the first part of
mystring
is also not great, since I have to do cmd unquoting, which is tricky to do on Windows.Xaeroxe commentedon Mar 25, 2022
@nico this API can’t help you accomplish that. In order to accomplish that you need a null value passed for lpApplicationName, which isn’t supported by std::process::Command. You’re probably best served by calling CreateProcessA directly at that point.
rfcbot commentedon Mar 25, 2022
🔔 This is now entering its final comment period, as per the review above. 🔔
rfcbot commentedon Apr 4, 2022
The final comment period, with a disposition to merge, as per the review above, is now complete.
As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.
This will be merged soon.
Rollup merge of rust-lang#92942 - Xaeroxe:raw_arg, r=dtolnay
JohnTitor commentedon May 22, 2022
Triage: I'm going to close this as the stabilization PR was merged already 🎉
Rollup merge of #92942 - Xaeroxe:raw_arg, r=dtolnay
raw_arg
forCommand
on specific platforms rust-lang/cargo#15179