dotnet/runtime

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

Open

#95,079 创建于 2023年11月21日

在 GitHub 查看
 (10 评论) (0 反应) (0 负责人)C# (5,445 fork)batch import
area-System.Consolehelp wanted

仓库指标

Star
 (17,886 star)
PR 合并指标
 (平均合并 12天 11小时) (30 天内合并 661 个 PR)

描述

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

贡献者指南