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

[API Proposal]: ProcessStartInfo.CreateSuspended, Process.Resume #94127

Open
sebastienros opened this issue Oct 28, 2023 · 4 comments
Open

[API Proposal]: ProcessStartInfo.CreateSuspended, Process.Resume #94127

sebastienros opened this issue Oct 28, 2023 · 4 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Diagnostics.Process
Milestone

Comments

@sebastienros
Copy link
Member

Background and motivation

Currently I use ProcessStartInfo/Process.Start to launch processes with overridden environment variables, redirect standard input and output, and so forth.

I now need to use the CREATE_SUSPENDED flag so that I can modify the process after it's created and before it starts actual execution, but there's no way to pass this flag into ProcessStartInfo/Process.Start. Given that I still need to use all the other features of ProcessStartInfo, the only reasonable path I can see forward is to either copy or reimplement the entirety of the System.Diagnostics.Process code.

My proposal would also be cross-platform.

API Proposal

namespace System.Diagnostics;

public sealed partial class ProcessStartInfo
{
    public bool CreateSuspended { get; set; }
}

public partial class Process
{
    public bool Resume();
}

API Usage

var process = new Process()
{
    StartInfo = {
        FileName = executable,
        CreateSuspended = true,
        CreateNoWindow = true, // for reference only, as it has the same characteristics
    }
};

process.Start();

// Do whatever is needed with the process...

process.Resume();

Alternative Designs

I don't think these issues are duplicates since they adopt a different design that doesn't seem to get traction.

#71515
#90581

NB: @hach-que I copied your proposal and tried to make the API easier to get through the review process.

Risks

No response

@sebastienros sebastienros added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Oct 28, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Oct 28, 2023
@ghost
Copy link

ghost commented Oct 28, 2023

Tagging subscribers to this area: @dotnet/area-system-diagnostics-process
See info in area-owners.md if you want to be subscribed.

Issue Details

Background and motivation

Currently I use ProcessStartInfo/Process.Start to launch processes with overridden environment variables, redirect standard input and output, and so forth.

I now need to use the CREATE_SUSPENDED flag so that I can modify the process after it's created and before it starts actual execution, but there's no way to pass this flag into ProcessStartInfo/Process.Start. Given that I still need to use all the other features of ProcessStartInfo, the only reasonable path I can see forward is to either copy or reimplement the entirety of the System.Diagnostics.Process code.

My proposal would also be cross-platform.

API Proposal

namespace System.Diagnostics;

public sealed partial class ProcessStartInfo
{
    public bool CreateSuspended { get; set; }
}

public partial class Process
{
    public bool Resume();
}

API Usage

var process = new Process()
{
    StartInfo = {
        FileName = executable,
        CreateSuspended = true,
        CreateNoWindow = true, // for reference only, as it has the same characteristics
    }
};

process.Start();

// Do whatever is needed with the process...

process.Resume();

Alternative Designs

I don't think these issues are duplicates since they adopt a different design that doesn't seem to get traction.

#71515
#90581

NB: @hach-que I copied your proposal and tried to make the API easier to get through the review process.

Risks

No response

Author: sebastienros
Assignees: -
Labels:

api-suggestion, area-System.Diagnostics.Process, untriaged

Milestone: -

@alexrp
Copy link
Contributor

alexrp commented Oct 28, 2023

To be clear, it's not that #71515 didn't have traction. The discussion landed on exposing "proper" properties for the various flags and options related to process creation (as you've done for bool CreateSuspended here), but the proposal should include all/most of the Windows process creation options so that API review can have a more complete picture of how the API might look later down the line, even if only parts of it are implemented initially. I just haven't had time to do that yet...

@jkotas jkotas changed the title [API Proposal]: [API Proposal]: ProcessStartInfo.CreateSuspended, Process.Resume Oct 28, 2023
@adamsitnik
Copy link
Member

As an end user, I would be happy to have it and use it in BenchmarkDotNet for some of the profiler plugins (cc @lihaMSFT)

As a maintainer I need to know whether it would be possible to implement it on Unix? (cc @tmds)

@jborean93
Copy link
Contributor

Just to add my 2 cents, this should be the last remaining feature that is needed by PowerShell to move away from custom PInvoke code to using System.Diagnostics.Process for all scenarios. Currently they rely on being able to create a suspended process so that they can configure a Job object of that new process before they resume it. Being able to use S.D.Process directly would be great as it solves other problems like not being able to create the Process object with an all access token from the one PowerShell spawned through CreateProcess*.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Diagnostics.Process
Projects
None yet
Development

No branches or pull requests

4 participants