Skip to content

pwsh.exe writes error messages to stdout when only stdout is redirected #26675

@zwhfly

Description

@zwhfly

Prerequisites

Steps to reproduce

Execute these commands in cmd.exe:

1>outfile pwsh.exe -Command "Write-Error TEST"
type outfile

Expected behavior

C:\temp>1>outfile pwsh.exe -Command "Write-Error TEST"
Write-Error: TEST

C:\temp>type outfile

C:\temp>

Actual behavior

C:\temp>1>outfile pwsh.exe -Command "Write-Error TEST"

C:\temp>type outfile
Write-Error: TEST

C:\temp>

Error details

Environment data

Name                           Value
----                           -----
PSVersion                      7.5.4
PSEdition                      Core
GitCommitId                    7.5.4
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

I'm executing pwsh in a cmd.exe console. When stdout is redirected to a file but stderr is not redirected, pwsh writes error messages to the file, while it should print the error in the cmd window.
When stdout and stderr are both redirected or neither redirected, the behavior seems correct.

C:\temp>pwsh.exe -Command "Write-Error TEST"
Write-Error: TEST        <= This line is red in color

C:\temp>1>outfile pwsh.exe -Command "Write-Error TEST"

C:\temp>type outfile
Write-Error: TEST        <= This line is red in color

C:\temp>1>outfile 2>errfile pwsh.exe -Command "Write-Error TEST"

C:\temp>type outfile

C:\temp>type errfile
Write-Error: TEST        <= This line is red in color

C:\temp>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.WG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions