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:
- Run the program below
- Once you see the
Streams disposed
message, press a character key - You’d expect to to see the message
Intercepted key: {key}
printed, but you don’t - Press a few other character keys, note that the program does not progress until you press the
enter
key - After the
enter
key has been pressed, press a single character key. Note that the messageIntercepted 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
- Added PipeSource and PipeTarget implementation for native piping directly to/from parent process. Fixes #79 — committed to OrgFlow/CliWrap by DaRosenberg 4 years ago
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?