Skip to content

Provide an API for std::process::Command to set CreateProcess flags on Windows #37827

Closed
@luser

Description

@luser

Updated report

Now a tracking issue for CommandExt::creation_flags on Windows.

Open questions:

  • Should we provide a method of adding flags as opposed to setting them entirely? Would be a bit more composition-friendly.

Also, don't forget to add to the prelude when stabilizing!

Original report

There's a currently-unused codepath in the Windows implementation of std::process::Command::spawn that can set DETATCHED_PROCESS:

flags |= c::DETACHED_PROCESS | c::CREATE_NEW_PROCESS_GROUP;

It looks like historically there was a method to set this but it got removed. Unfortunately there's currently no way to set this, and no other way to set the CreateProcess flags, so for a project I'm working on I basically had to reimplement spawn for Windows:
https://github.com/luser/sccache2/blob/89f4b44d01084846893a64137d965ee844fe2d72/src/commands.rs#L103

I think we need some way to set this, even if it's Windows-specific. There are a bunch of other flags that can be specified, so maybe a way to set arbitrary flags would be useful?
https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863(v=vs.85).aspx

I think this would fit nicely onto a Windows equivalent of the std::os::unix::process::CommandExt trait, maybe something like:

trait CommandExt {
  fn process_flags(&mut self, flags: u32) -> &mut Command
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-unstableBlocker: Implemented in the nightly compiler and unstable.O-windowsOperating system: WindowsT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions