Skip to content

Tracking Issue for windows_process_extensions_raw_arg #92939

@Xaeroxe

Description

@Xaeroxe
Contributor

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.

Activity

added
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
on Jan 15, 2022
Xaeroxe

Xaeroxe commented on Jan 15, 2022

@Xaeroxe
ContributorAuthor

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

m-ou-se

m-ou-se commented on Mar 9, 2022

@m-ou-se
Member

@rfcbot merge

rfcbot

rfcbot commented on Mar 9, 2022

@rfcbot
Collaborator

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.

added
proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.
on Mar 9, 2022
nico

nico commented on Mar 25, 2022

@nico

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

Xaeroxe commented on Mar 25, 2022

@Xaeroxe
ContributorAuthor

@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.

added
final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
on Mar 25, 2022
rfcbot

rfcbot commented on Mar 25, 2022

@rfcbot
Collaborator

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

removed
proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
on Mar 25, 2022
added
to-announceAnnounce this issue on triage meeting
and removed
final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
on Apr 4, 2022
rfcbot

rfcbot commented on Apr 4, 2022

@rfcbot
Collaborator

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.

added a commit that references this issue on Apr 4, 2022
c56cbf9
JohnTitor

JohnTitor commented on May 22, 2022

@JohnTitor
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nico@m-ou-se@apiraino@Xaeroxe@rfcbot

        Issue actions

          Tracking Issue for windows_process_extensions_raw_arg · Issue #92939 · rust-lang/rust