Tracking Issue for windows_process_extensions_raw_arg
Xaeroxe opened this issue · 8 comments
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
Unresolved Questions
- None yet.
I need a Rust team member to kick off an FCP for this.
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.
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.
@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.
🔔 This is now entering its final comment period, as per the review above. 🔔
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.
Triage: I'm going to close this as the stabilization PR was merged already 🎉