Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2650,7 +2650,8 @@ internal void Run(bool inputLoopIsNested)
}

#if UNIX
if (c.SupportsVirtualTerminal)
// Commands read from stdin don't use the cursor keys, so don't write DECCKM in that case
if (c.SupportsVirtualTerminal && !ui.ReadFromStdin)
{
// enable DECCKM as .NET requires cursor keys to emit VT for Console class
c.Write(DECCKM_ON);
Expand Down Expand Up @@ -2761,7 +2762,7 @@ e is RemoteException ||
else
{
#if UNIX
if (c.SupportsVirtualTerminal)
if (c.SupportsVirtualTerminal && !ui.ReadFromStdin)
{
// disable DECCKM to standard mode as applications may not expect VT for cursor keys
c.Write(DECCKM_OFF);
Expand Down
22 changes: 22 additions & 0 deletions test/powershell/Host/ConsoleHost.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,28 @@ foo
}
}

Context "Redirected standard input as commands" {
It "Does not write VT sequences to the output: <CommandLine>" -TestCases @(
@{CommandLine = "-noprofile -c -"}
@{CommandLine = "-noprofile -Command -"}
@{CommandLine = "-noprofile -File -"}
@{CommandLine = "-noprofile"}
) {
param($CommandLine)
$si = NewProcessStartInfo $CommandLine -RedirectStdIn
# NO_COLOR and TERM=dumb would hide the VT sequences, so make sure neither is set
$null = $si.Environment.Remove("NO_COLOR")
$si.Environment["TERM"] = "xterm-256color"
$process = RunPowerShell $si
$process.StandardInput.Write("'hello'`n")
$process.StandardInput.Close()
$output = $process.StandardOutput.ReadToEnd()
EnsureChildHasExited $process
$output | Should -Match "hello"
$output | Should -Not -Match "`e"
}
}

Context "Exception handling" {
BeforeAll {
# the default stack size in PowerShell is 10000000, set the stack
Expand Down