New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Console]::OutputEncoding doesn't work to parse exe with unicode output #10789
Comments
That's not good - the bug is still present as of PowerShell Core 7.0.0-preview.4. Here's a repro that doesn't require WSL: [Console]::OutputEncoding = [text.encoding]::unicode; sfc /? | Write-Output As a Pester test: [Console]::OutputEncoding = [text.encoding]::unicode; sfc /? | Write-Output | Should -Not -Match "`0" |
Has this ever worked in PowerShell Core, or has it been broken ever since 6.0.0? |
@vexx32: It's also broken in 6.0.0. |
This is due to a breaking change in .NET Core. You should initialize This is the code that creates |
If I understand correctly, then, a fix should be to set the Should this respect |
I don't know if it should use bool redirectStdOut = true;
bool redirectStdErr = true;
bool redirectStdIn = false;
var startInfo = new ProcessStartInfo();
if (redirectStdOut)
{
startInfo.RedirectStandardOutput = true;
startInfo.StandardOutputEncoding = Console.OutputEncoding;
}
if (redirectStdErr)
{
startInfo.RedirectStandardError = true;
startInfo.StandardErrorEncoding = Console.OutputEncoding;
}
if (redirectStdIn)
{
startInfo.RedirectStandardInput = true;
startInfo.StandardInputEncoding = Console.InputEncoding;
} |
Actually to match PS 5.1 behavior it should not use $OutputEncoding |
Agreed, @0xd4d: I don't know how
|
Thanks for looking into this, everyone. Hopefully this can get fixed soon. |
Yep. Note that C:\Windows\system32\sfc.exe in Windows 10 outputs utf-16. It's a powershell question that comes up occasionally. |
@mklement0 I guess that would mean |
@vexx32 I've only glanced at the code, and I see that the pipe that is connected to the child process' stdin explicitly uses PowerShell/src/System.Management.Automation/engine/NativeCommandProcessor.cs Lines 1797 to 1801 in 425bc36
I don't fully understand how that relates to the default |
@SvenGroot do you have any examples on the input side where we have issues with encoding? |
@SteveL-MSFT No, I only use OutputEncoding in my scenario. |
Here's my guess as to what we should do:
|
@mklement0 when not piping, what is value of setting |
@SteveL-MSFT: Thanks for the correction re 3rd bullet point - I've fixed my previous comment.
My thinking is: An interactive console application that reads from stdin probably expects the console's (terminal's) input encoding to be in effect ( |
Glad to see this was fixed for As for setting |
🎉This issue was addressed in #10824, which has now been successfully released as Handy links: |
Steps to reproduce
I have a Windows executable that produces unicode (utf-16) output. In PowerShell 5.1, I can set the [Console]::OutputEncoding property so the output of that command gets correctly interpreted. On PowerShell Core 6.2.3, that doesn't appear to work.
I've also tried setting [Console]::InputEncoding and $OutputEncoding, but the problem persists.
For example, I use the wsl.exe binary here, so this should repro on any system that has the Windows Subsystem for Linux installed.
Expected behavior
Actual behavior
Environment data
The text was updated successfully, but these errors were encountered: