Prerequisites
Steps to reproduce
- Have Git for Windows installed
- Run Powershell 7.21 (either in ConHost or the new Terminal app, bug is reproducible in both)
- Create the following simple function:
function Test-Ansi {
$VerbosePreference = 'Continue'
Write-Verbose '------ Before ------'
& "$Env:ProgramFiles\Git\usr\bin\patch.exe" --help > $null
Write-Verbose '------ After ------'
}
- Observe properly formatted coloring for the line before
- Observe line after being uncolored and ANSI sequences instead printed verbatim
Additional Notes
This behaviour was only observed in PowerShell 7 - running the same function on PowerShell 5 yields the expected behaviour with no breaking changes to the ANSI output.
It also doesn't make a difference whether the redirection is done via | Out-Null or doing a $null assignment. Even just redirecting stderr via 2>$null triggers the issue. Not redirecting the command is the only way to have it run without breaking.
The issue also occurs independent of invocation, Invoke-Expression results in this bug as does using Start-Command.
Also running this slightly tweaked function:
function Test-Ansi-Async {
$VerbosePreference = 'Continue'
Write-Verbose '------ Before ------'
Start-Process -FilePath "C:\Program Files\Git\usr\bin\patch.exe" -RedirectStandardOutput NUL -ArgumentList '--help' -NoNewWindow
Write-Verbose '------ After ------'
}
will yield different bugs in ConHost or Windows Terminal:
- In ConHost browsing through command history will have corrupted output, with characters remaining on screen between history items
- In Windows Terminal the ANSI color codes of the next command will be corruped
(See screenshots for each case).
In both cases pressing "Enter" without any input restores proper output at the prompt.
Expected behavior
VERBOSE: ------ Before ------
VERBOSE: ------ After ------
Actual behavior
VERBOSE: ------ Before ------
←[33;1mVERBOSE: ------ After ------←[0m
Error details
PS C:\Windows\System32› Get-Error
PS C:\Windows\System32›
Environment data
Name Value
---- -----
PSVersion 7.2.1
PSEdition Core
GitCommitId 7.2.1
OS Microsoft Windows 10.0.22000
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
Visual Corruption in ConHost

Broken ANSI Codes in Windows Terminal

Prerequisites
Steps to reproduce
Additional Notes
This behaviour was only observed in PowerShell 7 - running the same function on PowerShell 5 yields the expected behaviour with no breaking changes to the ANSI output.
It also doesn't make a difference whether the redirection is done via
| Out-Nullor doing a$nullassignment. Even just redirecting stderr via2>$nulltriggers the issue. Not redirecting the command is the only way to have it run without breaking.The issue also occurs independent of invocation,
Invoke-Expressionresults in this bug as does usingStart-Command.Also running this slightly tweaked function:
will yield different bugs in ConHost or Windows Terminal:
(See screenshots for each case).
In both cases pressing "Enter" without any input restores proper output at the prompt.
Expected behavior
Actual behavior
Error details
Environment data
Visuals
Visual Corruption in ConHost
Broken ANSI Codes in Windows Terminal