Process.Run/RunAsync(silent: true) still creates a console window when the parent is a GUI app
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- csharp
- Domain
- operating-systems
Research direction
The silent overloads in src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Scenarios.cs (around lines 202-211) only set the standard handles. CREATE_NO_WINDOW is applied only from startInfo.CreateNoWindow in SafeProcessHandle.Windows.cs (around line 283). Start by reading how that flag is chosen, then decide how silent should set it, possibly only when the parent has no console. Done when a silent child started from a WinExe parent shows no console window, and console parents keep their Ctrl+C behaviour.
Written by the indexing model from the issue text.
Description
Description
@adamsitnik
Process.Run and Process.RunAsync with silent: true redirect stdin/stdout/stderr to the null device, but don't set CreateNoWindow.
When the parent process has no console (e.g. a WinExe/GUI app), Windows allocates a new console for a console subsystem child, so you get an empty console window that flashes up for the lifetime of the child process. The child produces no output, as expected, but the window still appears.
I can't think of a scenario where someone would pass silent: true and want an empty console window to appear. I hit this in a GUI app (an IDE) that runs dotnet and git processes in the background.
Reproduction Steps
In a WinExe app (<OutputType>WinExe</OutputType>):
await Process.RunAsync("ping.exe", ["-n", "4", "127.0.0.1"], silent: true);
(ping is just used as a ~3 second sleep - timeout exits immediately when stdin is redirected to the null device.)
Expected behavior
I would expect that no console window is shown. I can't think of any scenario where you would want to redirect the standard handles to null, but also show a console window? (Which would show no output).
Actual behavior
An empty console window is shown until the child process exits.
Regression?
No, new API in .NET 11.
Known Workarounds
Use the ProcessStartInfo overload and set the handles and CreateNoWindow manually:
using SafeFileHandle nullHandle = File.OpenNullHandle();
var startInfo = new ProcessStartInfo("ping.exe", ["-n", "4", "127.0.0.1"])
{
CreateNoWindow = true,
StandardInputHandle = nullHandle,
StandardOutputHandle = nullHandle,
StandardErrorHandle = nullHandle,
};
await Process.RunAsync(startInfo);
Configuration
.NET 11.0.0 (SDK 11.0.100), also present on main. Windows 11, x64. Specific to Windows. Only reproduces when the parent has no console - from a console app, the child shares the parent's console so no window appears, which is likely why this wasn't noticed.
Other information
The silent overloads only set the standard handles:
CREATE_NO_WINDOW is only ever set from startInfo.CreateNoWindow:
silent was added in #129509 (API approved in #128453). Neither discussed console windows.
StartAndForget has the same behaviour - it redirects to the null device by default, but would still create a window.
One consideration - with CREATE_NO_WINDOW, a child of a console parent gets its own hidden console rather than sharing the parent's, so it would no longer receive Ctrl+C from the parent's console. Setting it only when the parent has no console (GetConsoleWindow() == IntPtr.Zero) would avoid changing behaviour for console parents.
- Dominant language
- C#
- Stars
- 18.5k
- Forks
- 5.8k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 588
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
area-CodeGen-coreclr untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
dotnet/runtime#138181 · 1 comment ·
Maintainers usually reply within 1 day
-
area-System.Collections untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
dotnet/runtime#138090 · 1 comment ·
Maintainers usually reply within 1 day
-
area-System.Text.Json untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
dotnet/runtime#138089 · 1 comment ·
Maintainers usually reply within 1 day
-
area-Setup untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
dotnet/runtime#137376 · 1 comment ·
Maintainers usually reply within 1 day
-
area-System.Memory untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
dotnet/runtime#137334 · 4 comments ·
Maintainers usually reply within 1 day
Similar issues
-
Add `net10.0`Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
dotnet-outdated/dotnet-outdated#871 ·
Maintainers usually reply within 1 day
-
triage/untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
unoplatform/uno#26676 ·
Maintainers usually reply within 1 day
-
.NET bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
jhaizhou-ops/S2Arm#2177 · 3 comments ·
Maintainers usually reply within 1 day