CliWrap: Console.OpenStandardInput() does not get properly released after using it as a pipe source

Using v 3.1.0:

After using .WithStandardInputPipe(PipeSource.FromStream(inputStream))), the input stream does not appear to be correctly relinquished once the command has finished executing.

Repro steps:

  1. Run the program below
  2. Once you see the Streams disposed message, press a character key
  3. You’d expect to to see the message Intercepted key: {key} printed, but you don’t
  4. Press a few other character keys, note that the program does not progress until you press the enter key
  5. After the enter key has been pressed, press a single character key. Note that the message Intercepted key: {key} is printed
using (var inputStream = Console.OpenStandardInput())
using (var errorStream = Console.OpenStandardError())
{
	var commandResult =
		await Cli.Wrap("git")
			.WithArguments("--version")
			.WithValidation(CommandResultValidation.None)
			.WithStandardInputPipe(PipeSource.FromStream(inputStream))
			.WithStandardOutputPipe(PipeTarget.ToStream(errorStream))
			.ExecuteBufferedAsync(Encoding.UTF8);
}

Console.WriteLine("Streams disposed");

var key = Console.ReadKey(intercept: true);

Console.WriteLine($"Intercepted key: {key.KeyChar}");

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 22 (12 by maintainers)

Commits related to this issue

Most upvoted comments

I think Console.ReadKey() might not even be using stdin directly, i.e. it reads key presses sent to the window.

Hmm… I think that’s unlikely, because it would never work cross-platform, in a macOS and Linux terminal environment the streams is the only thing a process has, no access to window handles and such. And it would also make it even weirder that Console.ReadKey() does not receive anything just because we’re mucking around with the input stream, no?