Skip to content

7.4.0 Invoking pwsh -Command with stdout redirection from within PowerShell results in CLIXML instead of actual output #20808

@twinter-amosfivesix

Description

@twinter-amosfivesix

Prerequisites

Steps to reproduce

I ran across this by accident while trying to workaround issue #20747.

If I'm using PowerShell 7.4.0 and I invoke pwsh with -Command and I redirect the output of pwsh to a file, that file ends up containing CLIXML with an encoded version of the output rather than the actual output, as happens in 7.3.10

When doing this with a script and pwsh -File things work as expected.

This appears to be related to the PR: Support byte stream piping between native commands and file redirection by @SeeminglyScience that was added in preview 4.

Expected behavior

PS> pwsh >x.txt -Command { Write-Output "Hello" }

PS> Get-Content x.txt
Hello

Actual behavior

PS> pwsh >x.txt -Command { Write-Output "Hello" }

PS> Get-Content x.txt
#< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Output">Hello</S></Objs>

Error details

No error invovled.

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
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

7.3.10

image

7.4.0

image

Metadata

Metadata

Labels

Needs-TriageThe issue is new and needs to be triaged by a work group.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions