Skip to content

Use Console.IsOutputRedirected instead of P/Invoke for redirect detection#2001

Open
tyrielv wants to merge 1 commit into
microsoft:masterfrom
tyrielv:tyrielv/fix-console-redirect-detection
Open

Use Console.IsOutputRedirected instead of P/Invoke for redirect detection#2001
tyrielv wants to merge 1 commit into
microsoft:masterfrom
tyrielv:tyrielv/fix-console-redirect-detection

Conversation

@tyrielv
Copy link
Copy Markdown
Contributor

@tyrielv tyrielv commented Jun 4, 2026

The previous IsConsoleOutputRedirectedToFile() used Win32 GetFileType to check if stdout was redirected to a disk file. This missed the pipe case (GetFileType returns Pipe, not Disk), so the console spinner would still run when stdout was captured via Process.Start with RedirectStandardOutput (e.g. in functional tests and CI), polluting captured output with \r and spinner characters.

Replace with .NET's Console.IsOutputRedirected which returns true for any non-console handle (files, pipes, NUL). Remove the now-unused P/Invoke declarations (GetStdHandle, GetFileType) and the platform abstraction (IsConsoleOutputRedirectedToFile) from GVFSPlatform, WindowsPlatform, GVFSHooksPlatform, and MockPlatform.

…tion

The previous IsConsoleOutputRedirectedToFile() used Win32 GetFileType to
check if stdout was redirected to a disk file. This missed the pipe case
(GetFileType returns Pipe, not Disk), so the console spinner would still
run when stdout was captured via Process.Start with RedirectStandardOutput
(e.g. in functional tests and CI), polluting captured output with \r and
spinner characters.

Replace with .NET's Console.IsOutputRedirected which returns true for any
non-console handle (files, pipes, NUL). Remove the now-unused P/Invoke
declarations (GetStdHandle, GetFileType) and the platform abstraction
(IsConsoleOutputRedirectedToFile) from GVFSPlatform, WindowsPlatform,
GVFSHooksPlatform, and MockPlatform.

Assisted-by: Claude Opus 4.6
Signed-off-by: Tyrie Vella <tyrielv@gmail.com>
@tyrielv tyrielv marked this pull request as ready for review June 4, 2026 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant