diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs index 1538c2cb5..209d2385d 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs @@ -1557,6 +1557,7 @@ namespace Microsoft.PowerShell if (initialContent != null) { sb.Append(initialContent); + sb.Append('\n'); } while (true) @@ -1579,7 +1580,11 @@ namespace Microsoft.PowerShell if (!NoPrompt) Console.Out.Write('\n'); Console.In.Read(); } - sb.Append('\n'); + break; + } + + if (c == '\n') + { break; } @@ -1591,12 +1596,6 @@ namespace Microsoft.PowerShell { sb.Append(c); } - - - if (c == '\n') - { - break; - } } return sb.ToString(); diff --git a/test/powershell/Host/ConsoleHost.Tests.ps1 b/test/powershell/Host/ConsoleHost.Tests.ps1 index bfca2f340..1eae8b598 100644 --- a/test/powershell/Host/ConsoleHost.Tests.ps1 +++ b/test/powershell/Host/ConsoleHost.Tests.ps1 @@ -263,8 +263,23 @@ Describe "ConsoleHost unit tests" -tags "Feature" { $si = NewProcessStartInfo "-noprofile -" -RedirectStdIn $process = RunPowerShell $si $process.StandardInput.Write("1+1`n") + $process.StandardOutput.ReadLine() | Should Be "2" + + # Multi-line input + $process.StandardInput.Write("if (1)`n{`n 42`n}`n`n") + $process.StandardOutput.ReadLine() | Should Be "42" + $process.StandardInput.Write(@" +function foo +{ + 'in foo' +} + +foo + +"@) + $process.StandardOutput.ReadLine() | Should Be "in foo" + $process.StandardInput.Close() - $process.StandardOutput.ReadToEnd() | Should Be "2${nl}" EnsureChildHasExited $process }