dotnet/runtime

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

Open

#95.079 aperta il 21 nov 2023

Vedi su GitHub
 (10 commenti) (0 reazioni) (0 assegnatari)C# (5445 fork)batch import
area-System.Consolehelp wanted

Metriche repository

Star
 (17.886 star)
Metriche merge PR
 (Merge medio 12g 11h) (661 PR mergiate in 30 g)

Descrizione

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

Guida contributor