Process.Run/RunAsync(silent: true) still creates a console window when the parent is a GUI app
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- csharp
- Lĩnh vực
- operating-systems
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- C#
- Star
- 18.5k
- Fork
- 5.8k
- Merge trung bình
- 2 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 588
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của dotnet/runtime
-
area-CodeGen-coreclr untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
dotnet/runtime#138181 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area-System.Collections untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
dotnet/runtime#138090 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area-System.Text.Json untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
dotnet/runtime#138089 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area-Setup untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
dotnet/runtime#137376 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area-System.Memory untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
dotnet/runtime#137334 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của dotnet/runtime
Issue tương tự
-
Add `net10.0`Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Wishlist Navigation Does Not Redirect to the User's Own Wishlist from a Shared Wishlist PageĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
nopSolutions/nopCommerce#8484 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
account effort:S P3 refactor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
nightscout/nocturne#4119 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
dotnet-outdated/dotnet-outdated#871 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
triage/untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
unoplatform/uno#26676 ·
Maintainer thường phản hồi trong vòng 1 ngày