Skip to content

ConsoleHost tests fail with interactive use and redirected stdin #625

Description

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 exit

This 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

Activity

  1. lzybkr commented on Jan 23, 2018

    @lzybkr
    Contributor

    It's possible this is related to #618 - as in, the fix might fix both.

  2. daxian-dbw commented on Mar 16, 2018

    @daxian-dbw
    Member

    Jason Shirk (@lzybkr) I found when running on Windows, PSReadline detects whether the standard input or output is redirected, and in such a case, it will throw an NotSupportedException to let PowerShell handles the input.
    The code is at PlatformWindows.Init.

    However, it doesn't do the same on Unix platforms, and eventually Console.KeyAvailable throws an InvalidOperationException from ReadOneOrMoreKeys() because the stdin is redirected.

    Is it intentional for PSReadline to handle input and output on Unix even if stdin or stdout is redirected? Note that in the version of PSReadline that is currently used in PSCore, we throw NotSupportedException on all platforms when stdin or stdout is redirected.

  3. lzybkr commented on Mar 16, 2018

    @lzybkr
    Contributor

    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 PSReadLine worked in docker, so I might be wrong here.

  4. daxian-dbw commented on Mar 16, 2018

    @daxian-dbw
    Member

    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 PSReadline in such cases on all platforms. I will submit a PR to make PSReadline throw NotSupportedException on Unix too, in case that stdin or stdout is redirected.

    For #618, if it always happens when running in a container, then it would become a blocking issue for PSCore use PSReadline 2.0 by default. Will look into that later.

  5. added a commit that references this issue on Mar 20, 2018
    62cf9f8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions