-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Description
When targeting .NET Core 3.x (netcoreapp3.0 and netcoreapp3.1), a call to StreamReader::ReadLine with the standard input Stream as the underlying stream does not 'echo' typed characters at the terminal on macOS/Linux IF a call to Console.ReadLine has been made before.
This issue does not occur when targetting netcoreapp2.1; both Console.ReadLine and StreamReader::ReadLine echo typed characters.
using System;
using System.IO;
class Program
{
// Only repros in .NET Core 3.1
static void Main(string[] args)
{
// Comment this line out and echo with StreamReader:ReadLine works
string consoleText = Console.ReadLine();
var stdin = Console.OpenStandardInput();
using (var sr = new StreamReader(stdin))
{
// Does not echo if the Console.ReadLine call has been executed
string readerText = sr.ReadLine();
}
}
}<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<!-- Does not repro if you target .NET Core 2.1 -->
<!--<TargetFramework>netcoreapp2.1</TargetFramework>-->
</PropertyGroup>
</Project>$ dotnet run
hello<return> # Console.ReadLine
<typed characters here do not echo><return> # StreamReader.ReadLine
<program exit>Configuration
OSs
- Ubuntu 20.04 LTS x86_64
- macOS 10.15 Catalina x86_64
Target Frameworks
- netcoreapp3.0
- netcoreapp3.1
Installed SDK
3.1.301
Regression?
Yes. When targeting .NET Core 2.1 this does not repro.
Other information
I know there have been many issues in this space over in prior releases in order to support ReadKey(intercept: true) on *nix systems. I imagine there's a problem in the initialisation of the console and terminal options for echo since this only happens if you interact with the console and standard input stream via Console.ReadLine before.