Repository navigation
ConsoleHost tests fail with interactive use and redirected stdin #625
Description
Activity
It's possible this is related to #618 - as in, the fix might fix both.
Jason Shirk (@lzybkr) I found when running on Windows,
PSReadlinedetects whether the standard input or output is redirected, and in such a case, it will throw anNotSupportedExceptionto let PowerShell handles the input.
The code is atPlatformWindows.Init.However, it doesn't do the same on Unix platforms, and eventually
Console.KeyAvailablethrows anInvalidOperationExceptionfromReadOneOrMoreKeys()because the stdin is redirected.Is it intentional for
PSReadlineto handle input and output on Unix even if stdin or stdout is redirected? Note that in the version ofPSReadlinethat is currently used in PSCore, we throwNotSupportedExceptionon all platforms when stdin or stdout is redirected.Dongbo Wang (@daxian-dbw) - For some reason I thought corefx would handle redirected input because it's technically feasible to do so on Unix with a proper tty, but I see that they don't, and instead match Windows by throwing, see here.
Parker Snell (@parkovski) implemented the necessary support for redirected input on Windows, most of that code would actually work for the most common terms on Unix, but corefx would have better support for more terminals because it reads the term database.
So I do think it is a scenario that needs to be supported, but it should be fine to disable for now.
As long as you are dealing with this issue, I wonder if #618 is related, it's possible docker is using redirected input as well, though I thought
PSReadLineworked in docker, so I might be wrong here.So far, I don't see this issue is related to #618. But I didn't debug in a container, so no guarantee yet.
So I do think it is a scenario that needs to be supported, but it should be fine to disable for now.
So I guess redirected standard input/output will be supported by PSReadline in future, but for now, it's OK to disable
PSReadlinein such cases on all platforms. I will submit a PR to makePSReadlinethrowNotSupportedExceptionon Unix too, in case thatstdinorstdoutis redirected.For #618, if it always happens when running in a container, then it would become a blocking issue for PSCore use
PSReadline 2.0by default. Will look into that later.- added a commit that references this issue
on Mar 20, 2018
ConsoleHost tests fail with redirected stdin with interactive use. The error seen is:
An error has occurred that was not properly handled. Additional information is shown below. The PowerShell process will exitThis failure is not seen on PSReadLine v1.2.
These failures are only seen on non-windows platforms.
Environment data
PS version: 6.0.0-rc.2
PSReadline version: 2.0.0-beta1
os: Linux aditya-ubuntu 4.4.0-109-generic #132-Ubuntu SMP Tue Jan 9 19:52:39 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Steps to reproduce or exception report
Execute the tests at: https://github.com/PowerShell/PowerShell/blob/master/test/powershell/Host/ConsoleHost.Tests.ps1#L335