Repository navigation
Closed
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.
Description
Steps to reproduce
$p = [Diagnostics.Process]::new()
$p.StartInfo.FileName = "pwsh"
$encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes("throw 'boom'"))
$p.StartInfo.Arguments = "-EncodedCommand $encoded -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -OutputFormat text"
$p.StartInfo.UseShellExecute = $false
$p.StartInfo.RedirectStandardError = $true
$p.Start() | Out-Null
$p.StandardError.ReadToEnd()Expected behavior
The error is written to stderr as text:
boom
At line:1 char:1
+ throw 'boom'
+ ~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (boom:String) [], RuntimeException
+ FullyQualifiedErrorId : boom
Changing $p.StartInfo.RedirectStandardError to $false (the default) will result in the expected output.
Actual behavior
The error record is encoded as CLIXML before being written to stderr:
#< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">boom_x000D__x000A_</S><S S="Error">At line:1 char:1_x000D__x000A_</S><S S="Error">+ throw 'boom'_x000D__x000A_</S><S S="Error">+ ~~~~~~~~~~~~_x000D__x000A_</S><S S="Error">+ CategoryInfo : OperationStopped: (boom:String) [], RuntimeException_x000D__x000A_</S><S S="Error">+ FullyQualifiedErrorId : boom_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>
This problem doesn't seem to apply to stdout. Setting $p.StartInfo.RedirectStandardOutput = $true in a similar fashion works as expected.
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.0
PSEdition Core
GitCommitId v6.0.0
OS Microsoft Windows 10.0.16299
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Reacted by roldengarm and Martin Gill
Metadata
Metadata
Assignees
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.
Activity
bugoutfr commentedon May 14, 2018
Hi,
I have the same problem here. The parent Powershell script is launched by Gitlab Runner which doesn't output to the standard output. With this configuration I end up with a messy mixed XMLCLI and normal text output instead of only the requested Text output.
Sample command line :
pwsh.exe -NoLogo -NonInteractive -NoProfile -OutputFormat Text -Command { [...] }Regards.
MartinSGill commentedon Oct 11, 2018
Any progress on this? It's really annoying in our build logs. I'd love to try and fix this myself.. but I've no idea where to look :(.
MartinSGill commentedon Oct 23, 2018
Seems to have happened before and seems related to -EncodedCommand
hashicorp/packer#4322
SteveL-MSFT commentedon Oct 24, 2018
Looking in the code it appears this is by-design, but I don't know why this is the case. Jason Shirk (@lzybkr) do you recall or know why we force XML in this case?
lzybkr commentedon Oct 24, 2018
I don't recall any history (the code comes from V1 I believe, before my time).
I'm guessing that code ignored the case where
OutputFormatwas specified explicitly. It makes sense to implicitly change to XML ifOutputFormatis not specified - with the assumption being that you're piping PowerShell to PowerShell.SteveL-MSFT commentedon Oct 24, 2018
Ok, that makes sense. So I can just modify it so that if
OutputFormatwas specified explicitly, we should honor that.Honor `-OutputFormat` if specified in noninteractive, redirected, enc…
TishSerg commentedon Apr 12, 2022
How about this fix for PowerShell 5.1.* branch?
powershell: fix unwanted progress streams leaking to output
powershell: fix unwanted progress streams leaking to output
Honor `-OutputFormat` if specified in noninteractive, redirected, enc…