Fix stderr output of console host to respect NO_COLOR by SteveL-MSFT · Pull Request #24391 · PowerShell/PowerShell
| It 'No_COLOR should be respected for redirected output' { | ||
| $psi = [System.Diagnostics.ProcessStartInfo] @{ | ||
| FileName = 'pwsh' | ||
| # Pass a command that succeeds and normally produces colored output, and one that produces error output. | ||
| Arguments = '-NoProfile -Command Get-Item .; Get-Content \nosuch123' | ||
| # Redirect (capture) both stdout and stderr. | ||
| RedirectStandardOutput = $true | ||
| RedirectStandardError = $true | ||
| } | ||
| $psi.Environment.Add('NO_COLOR', 1) | ||
| ($ps = [System.Diagnostics.Process]::Start($psi)).WaitForExit() | ||
| $ps.StandardOutput.ReadToEnd() | Should -Not -Contain '\e' | ||
| $ps.StandardError.ReadToEnd() | Should -Not -Contain '\e' | ||
| } |