-
Notifications
You must be signed in to change notification settings - Fork 8.2k
PowerShell pipe default OutputEncoding should match [System.Console]::OutputEncoding to avoid encoding issues with native console tools like more #25698
Copy link
Copy link
Open
Labels
Needs-TriageThe issue is new and needs to be triaged by a work group.The issue is new and needs to be triaged by a work group.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtimeWG-NeedsReviewNeeds a review by the labeled Working GroupNeeds a review by the labeled Working Group
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
When executing commands like:
echo 中文文本 | more
the output is garbled (涓枃鏂囨湰) because PowerShell's default $OutputEncoding is UTF-8, but native Windows console tools expect the console encoding (e.g. GB2312).
To improve compatibility, it is recommended that PowerShell by default sets:
$OutputEncoding = [System.Console]::OutputEncoding
unless the user explicitly overrides it. Because after executing $OutputEncoding = [System.Console]::OutputEncoding, commands like echo 中文文本 | more work correctly without garbled output.
This change would prevent common encoding mismatches in pipelines and improve interoperability with native Windows console tools.
Expected behavior
echo 中文文本 | more
中文文本Actual behavior
echo 中文文本 | more
涓枃鏂囨湰Error details
Environment data
Name Value
---- -----
PSVersion 7.5.2
PSEdition Core
GitCommitId 7.5.2
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Visuals
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Needs-TriageThe issue is new and needs to be triaged by a work group.The issue is new and needs to be triaged by a work group.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtimeWG-NeedsReviewNeeds a review by the labeled Working GroupNeeds a review by the labeled Working Group
