Skip to content

System.Diagnostics.Process with CreateNoWindow does not redirect stdout/stderr to parent process #68259

@mxschmitt

Description

@mxschmitt

Description

When using System.Diagnostics.Process with CreateNoWindow = true the output does not get redirected to the parent process. It will end up in no output.

The docs don't say anything about this behaviour, thats why I'm opening this issue and CreateNoWindow changes the behaviour if stdout/err gets redirected or not.

Reproduction Steps

using System.Diagnostics;

if (args.Length >= 1 && args[0] == "--start-process")
{
    var currentExecutable = Environment.ProcessPath;
    if (currentExecutable == null)
    {
        Console.Error.WriteLine("Could not get current executable path");
        return;
    }
    var playwrightStartInfo = new ProcessStartInfo(currentExecutable)
    {
        UseShellExecute = false,
        RedirectStandardError = false,
        RedirectStandardOutput = false,
        CreateNoWindow = true,
    };

    using var pwProcess = new Process()
    {
        StartInfo = playwrightStartInfo,
    };

    pwProcess.Start();
    pwProcess.WaitForExit();
}
else
{
    Console.WriteLine("Hello stdout!");
    Console.Error.WriteLine("Hello stderr!");
}

Run it with ./bin/Debug/net6.0/dotnetrepro.exe --start-process.

Expected behavior

Hello stderr! and Hello stdout! are getting printed.

Actual behavior

They get not printed.

Regression?

No response

Known Workarounds

Remove CreateNoWindow = true.

or:

Using RedirectStandardError = true and RedirectStandardOutput = true and manually redirecting it to the parent stdout/stderr.

Configuration

I can only reproduce it on Windows 10 + 11 amd64.

Other information

PS C:\Users\maxsc\Desktop\dotnet-process-redirect-issue> dotnet --list-sdks
6.0.102 [C:\Program Files\dotnet\sdk]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions