Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking Issue for windows_process_extensions_raw_arg #92939

Closed
3 tasks done
Xaeroxe opened this issue Jan 15, 2022 · 8 comments
Closed
3 tasks done

Tracking Issue for windows_process_extensions_raw_arg #92939

Xaeroxe opened this issue Jan 15, 2022 · 8 comments
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@Xaeroxe
Copy link
Contributor

Xaeroxe commented Jan 15, 2022

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.
@Xaeroxe Xaeroxe added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jan 15, 2022
@Xaeroxe
Copy link
Contributor Author

Xaeroxe commented Jan 15, 2022

I need a Rust team member to kick off an FCP for this.

@m-ou-se
Copy link
Member

m-ou-se commented Mar 9, 2022

@rfcbot merge

@rfcbot
Copy link

rfcbot commented 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.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Mar 9, 2022
@nico
Copy link

nico commented 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
Copy link
Contributor Author

Xaeroxe commented 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 rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Mar 25, 2022
@rfcbot
Copy link

rfcbot commented Mar 25, 2022

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Mar 25, 2022
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Apr 4, 2022
@rfcbot
Copy link

rfcbot commented 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.

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Apr 4, 2022
stabilize windows_process_extensions_raw_arg

Stabilizes the feature tracked at rust-lang#92939
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Apr 21, 2022
@JohnTitor
Copy link
Member

Triage: I'm going to close this as the stabilization PR was merged already 🎉

workingjubilee pushed a commit to tcdi/postgrestd that referenced this issue Sep 15, 2022
stabilize windows_process_extensions_raw_arg

Stabilizes the feature tracked at rust-lang/rust#92939
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants