dotnet/runtime

Console.IsInputRedirected returns true on git bash when there is no redirected input

Open

#95,079 opened on Nov 21, 2023

View on GitHub
 (10 comments) (0 reactions) (0 assignees)C# (5,445 forks)batch import
area-System.Consolehelp wanted

Repository metrics

Stars
 (17,886 stars)
PR merge metrics
 (Avg merge 12d 11h) (661 merged PRs in 30d)

Description

Description

Hi,

I have command-line tool (roslynator) that tries to read redirected input and use it as an input for the program (in my case it's a list of solutions to be analyzed).

Example code:

get-solution-paths | roslynator analyze

For this purpose I use Console.IsInputRedirected which works fine on Windows Terminal with Powershell.

The problem is that when I run just roslynator analyze on git bash (git-bash.exe) Console.IsInputRedirected returns true and then the execution is blocked when program tries to read input from console (when there is no redirected input):

https://github.com/dotnet/roslynator/blob/e030192b1dc5359df48e5dd15af79b5c807f481c/src/CommandLine/ConsoleHelpers.cs#L20

Thanks for help in advance.

Reproduction Steps

  1. dotnet tool install roslynator.dotnet.cli -g --version 0.7.2
  2. run git-bash.exe from git installation folder
  3. from git bash run roslynator analyze <PATH-TO-SOLUTION> -v diag
  4. The execution is blocked when program tries to read redirected input

Expected behavior

Console.IsInputRedirected should return false when there is no redirected input

Actual behavior

Console.IsInputRedirected returns true on git bash when there is no redirected input.

Regression?

No response

Known Workarounds

Set timeout for a task that tries to read redirected input:

Task<IEnumerable<string>> task = ConsoleHelpers.ReadRedirectedInputAsLines();

if (task.Wait(TimeSpan.FromMilliseconds(1000)))
{
}

Configuration

  • Windows 10 Pro x64
  • .NET SDK 8.0.100
  • git 2.42.0.windows.2

Other information

No response

Contributor guide