PowerShell / PowerShell/PowerShell

PowerShell pipe default OutputEncoding should match [System.Console]::OutputEncoding to avoid encoding issues with native console tools like `more`

Open
#25,698 22 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs-Triage WG-Engine WG-NeedsReview
Dominant language
C#
Stars
55.5k
Forks
8.5k
Avg merge
1d 2h
Merged PRs (30d)
88

Description

Prerequisites
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.0
Visuals

Image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue on Windows with echo 中文文本 | more, then trace how the pipeline uses $OutputEncoding and how [System.Console]::OutputEncoding is obtained. The work is done when the default behavior produces readable native-console output without overriding $OutputEncoding, while explicit overrides continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.