diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs index 3334357812..79b390d045 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs @@ -1653,7 +1653,17 @@ namespace Microsoft.PowerShell /// public override Size WindowSize { - get { return new Size(Console.WindowWidth, Console.WindowHeight); } + get + { + if (Console.IsOutputRedirected) + { + return WrapSize; + } + else + { + return new Size(Console.WindowWidth, Console.WindowHeight); + } + } set { Console.SetWindowSize(value.Width, value.Height); } } diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs index 9c7333ca85..90893506fd 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs @@ -1148,7 +1148,7 @@ namespace Microsoft.PowerShell // we leave a 1-cell margin on the end because if the very last character butts up against the // edge of the screen buffer, then the console will wrap the line. - List lines = WrapText(text, RawUI.BufferSize.Width - 1); + List lines = WrapText(text, RawUI.WindowSize.Width - 1); int count = 0; foreach (string s in lines) {