Skip to content
Merged
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 @@ -1396,6 +1396,7 @@ public override void WriteErrorLine(string value)
}
else
{
value = GetOutputString(value, SupportsVirtualTerminal);
Console.Error.WriteLine(value);
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/powershell/Host/ConsoleHost.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1203,4 +1203,19 @@ Describe 'TERM env var' -Tag CI {
$env:NO_COLOR = $null
}
}

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'
}
Comment on lines +1207 to +1220
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is passed for me in pwsh before the change... Nevertheless the change works for me in console if I manually set the env variable in cmd.exe and then run pwsh.

Copy link

@cf-rdegregory cf-rdegregory Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I specifically noticed the original issue when running PowerShell inside a Docker container (for example, using mcr.microsoft.com/powershell:7.5-alpine-3.17). I'd imagine the env var injection into the pwsh process in that scenario is similar to running pwsh from cmd.exe, and why the issue is reproducible by setting the env var outside of pwsh first.

}
Loading