From c5df728176f05cd906535791a61aeea5b1b2f209 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 1 Jul 2016 11:51:12 -0700 Subject: [PATCH] Import PSReadLine change to throw when redirected A similar change was made to the Source Depot fork of PSReadLine, and the behavior is depended on in the ConsoleHost. The host always attempts to load PSReadLine, because a future version of PSReadLine will support redirected input/output, and until then, PSReadLine must throw so that the host correctly falls back to Console.ReadLine(). --- src/Microsoft.PowerShell.PSReadLine/ReadLine.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Microsoft.PowerShell.PSReadLine/ReadLine.cs b/src/Microsoft.PowerShell.PSReadLine/ReadLine.cs index 58a9591dbe..aabf5a46a6 100644 --- a/src/Microsoft.PowerShell.PSReadLine/ReadLine.cs +++ b/src/Microsoft.PowerShell.PSReadLine/ReadLine.cs @@ -258,6 +258,14 @@ namespace Microsoft.PowerShell public static string ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics) { var console = _singleton._console; + + // If either stdin or stdout is redirected, PSReadline doesn't really work, so throw + // and let PowerShell call Console.ReadLine or do whatever else it decides to do. + if (Console.IsInputRedirected || Console.IsOutputRedirected) + { + throw new NotSupportedException(); + } + #if CORECLR _singleton._prePSReadlineControlCMode = Console.TreatControlCAsInput; #else