Process.Run/RunAsync(silent: true) still creates a console window when the parent is a GUI app
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- csharp
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- C#
- 星标
- 18.5k
- 派生
- 5.8k
- 平均合并
- 2 天 18 小时
- 30 天内合并 PR
- 588
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
dotnet/runtime 的其他 Issue
-
area-CodeGen-coreclr untriaged
难度 2/5 1-3 小时 新手友好度 65/100
dotnet/runtime#138181 · 1 条评论 ·
维护者通常 1 天内回复
-
area-System.Collections untriaged
难度 2/5 1-3 小时 新手友好度 82/100
dotnet/runtime#138090 · 1 条评论 ·
维护者通常 1 天内回复
-
area-System.Text.Json untriaged
难度 2/5 1-3 小时 新手友好度 72/100
dotnet/runtime#138089 · 1 条评论 ·
维护者通常 1 天内回复
-
area-Setup untriaged
难度 2/5 1-3 小时 新手友好度 76/100
dotnet/runtime#137376 · 1 条评论 ·
维护者通常 1 天内回复
-
area-System.Memory untriaged
难度 2/5 1-3 小时 新手友好度 75/100
dotnet/runtime#137334 · 4 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
A: Mapping P3: Standard T: New Feature
难度 2/5 1-3 小时 新手友好度 68/100
space-wizards/space-station-14#46878 · 2 条评论 ·
维护者通常 1 天内回复
-
Add `net10.0`未关闭
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 65/100
nopSolutions/nopCommerce#8484 ·
维护者通常 4 天内回复
-
account effort:S P3 refactor
难度 2/5 1-3 小时 新手友好度 78/100
nightscout/nocturne#4119 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
dotnet-outdated/dotnet-outdated#871 ·
维护者通常 1 天内回复