dotnet/runtime

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

Open

#95 079 ouverte le 21 nov. 2023

Voir sur GitHub
 (10 commentaires) (0 réactions) (0 assignés)C# (5 445 forks)batch import
area-System.Consolehelp wanted

Métriques du dépôt

Stars
 (17 886 stars)
Métriques de merge PR
 (Merge moyen 12j 11h) (661 PRs mergées en 30 j)

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

Guide contributeur