Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8f61400
Write piped human-readable output in the console code page (#6704)
soredake Nov 23, 2026
a816f06
Propagate piped output write failures and detect consoles properly
soredake Nov 24, 2026
44a1f1d
Keep stream state on restore and stop replaying partial writes
soredake Nov 24, 2026
d043a21
Potential fix for pull request finding 'Update PowerShell's cached ouโ€ฆ
soredake Nov 26, 2026
14d0228
Case the ChannelStreams test tag so spell checking splits it
soredake Nov 26, 2026
0bdc562
Find the complete UTF-8 boundary with ICU instead of hand-written parโ€ฆ
soredake Nov 26, 2026
5a37a8a
Convert piped output with a single MultiByteToWideChar call
soredake Nov 26, 2026
ec1eecd
Keep the output encoding and the console code page in agreement
soredake Nov 26, 2026
302c73f
Add a --piped-encoding argument to override the setting for one invocโ€ฆ
soredake Nov 26, 2026
62ed9d9
Cover the piped output encoding with E2E tests
soredake Nov 26, 2026
82c9d66
Report failed final writes and synchronization when restoring the stream
soredake Nov 26, 2026
42e7bbb
Keep the console in UTF-8 while the error stream writes to it
soredake Nov 26, 2026
34137d7
Apply the piped encoding override before argument validation
soredake Nov 26, 2026
71ab9b3
Assert the best-fit id in the console code page test
soredake Nov 26, 2026
80bc1c2
Rename the piped encoding option to output encoding
soredake Dec 2, 2026
05296ee
Shorten the output encoding argument description
soredake Dec 2, 2026
4adc774
Move the console code page and output encoding into the reporter
soredake Dec 2, 2026
a49387e
Apply the output encoding argument in UpdateForArgs
soredake Dec 2, 2026
02af947
Document how the profile encoding mitigation interacts with the conveโ€ฆ
soredake Dec 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions doc/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,23 @@ The `locale` setting selects the language used to resolve winget interface strin
},
```

### encoding

The `encoding` setting controls how human-readable output is encoded. It matters most when winget's standard output is redirected to a pipe, as it is inside a PowerShell pipeline.

A console host decodes the output of a native command with the code page that was active before the command started; PowerShell, for example, decodes native command output with the console output code page. The default `console` value writes human-readable output in that code page, so that localized text such as package names displays correctly. Characters that the code page cannot represent are written as `?`, and characters that the code page has a closest equivalent for use that equivalent. On a system whose console uses code page 866, for example, the `โ€ฆ` table truncation marker is written as `:` and Japanese or Ukrainian `ั–`/`า‘` characters are written as `?`.

Set the value to `utf8` to always write UTF-8, for example when the other end of the pipe is a script or tool that expects UTF-8. Machine-readable output (such as the JSON output of the DSC commands) and completion output are always written as UTF-8. Output that the operating system redirects to a file is not converted either.
Comment thread
soredake marked this conversation as resolved.
Resolved

> [!NOTE]
> The `--output-encoding` argument overrides this setting for a single invocation and accepts the same values.

```json
"output": {
"encoding": "utf8"
},
```

## Experimental Features

To allow work to be done and distributed to early adopters for feedback, settings can be used to enable "experimental" features.
Expand Down
32 changes: 32 additions & 0 deletions doc/release-notes/1.31/4507-powershell-piped-utf8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## Bug Fixes

### Redirected human-readable output uses the console code page

Human-readable output that is redirected to a pipe is now written in the console's output code
page instead of UTF-8. A console host decodes the output of a native command with the code page
that was active before the command started, so `winget list --source winget | Sort-Object Name`
in PowerShell on a Russian or Ukrainian system now displays localized package names instead of
garbled text (https://github.com/microsoft/winget-cli/issues/4507).

The conversion only applies while standard output is a pipe and the code page is not already
UTF-8. Output that the operating system redirects to a file is not converted, and
machine-readable channels (such as the JSON output of the DSC commands) and completion output
always stay UTF-8.

Characters that the console code page cannot represent are written as `?`, and characters that

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this reason, I'm not sure we can make console the default behavior.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JohnMcPMS In my opinion it's better than what I get without this pr:

ะทะพะฑั€ะฐะถะตะฝะฝั

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens with this change when you apply the well-known mitigation of setting the encodings in $PROFILE?

the code page has a closest equivalent for use that equivalent. On a system whose console uses
code page 866, for example, the `โ€ฆ` table truncation marker is written as `:`, and Japanese or
Ukrainian `ั–`/`า‘` characters are written as `?`. For lossless output in PowerShell, set
`[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()` to update both the console
code page and PowerShell's cached decoder. Use a UTF-8-capable terminal such as
[Windows Terminal](https://github.com/microsoft/terminal). For tools that already expect UTF-8,
set the new [`output.encoding`](https://github.com/microsoft/winget-cli/blob/master/doc/Settings.md#encoding)
setting to `utf8`, or pass `--output-encoding utf8` to a single command.

Profiles that already apply the mitigation in `$PROFILE` keep working: they set the console code
page to UTF-8 before WinGet starts, so WinGet sees a UTF-8 code page and writes UTF-8 without
converting anything.

This works around the console host decoding behavior. The underlying PowerShell issues are
https://github.com/PowerShell/PowerShell/issues/28496 and
https://github.com/PowerShell/PowerShell/issues/28498.
9 changes: 9 additions & 0 deletions schemas/JSON/settings/settings.schema.0.2.json
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,15 @@
"zh-CN",
"zh-TW"
]
},
"encoding": {
"description": "Encoding of human-readable output",
"type": "string",
"enum": [
"console",
"utf8"
],
"default": "console"
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/AppInstallerCLICore/Argument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ namespace AppInstaller::CLI
return { type, "open-logs"_liv, "logs"_liv };
case Execution::Args::Type::OutputLocale:
return { type, "output-locale"_liv, ArgTypeCategory::None };
case Execution::Args::Type::OutputEncoding:
return { type, "output-encoding"_liv, ArgTypeCategory::None };
case Execution::Args::Type::Force:
return { type, "force"_liv, ArgTypeCategory::CopyFlagToSubContext };
case Execution::Args::Type::OutputFile:
Expand Down Expand Up @@ -482,6 +484,8 @@ namespace AppInstaller::CLI
return Argument{ type, Resource::String::OpenLogsArgumentDescription, ArgumentType::Flag, Argument::Visibility::Help };
case Args::Type::OutputLocale:
return Argument{ type, Resource::String::OutputLocaleArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help };
case Args::Type::OutputEncoding:
return Argument{ type, Resource::String::OutputEncodingArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help };
case Args::Type::UninstallPrevious:
return Argument{ type, Resource::String::UninstallPreviousArgumentDescription, ArgumentType::Flag, Argument::Visibility::Help };
case Args::Type::Force:
Expand Down Expand Up @@ -529,6 +533,7 @@ namespace AppInstaller::CLI
args.push_back(ForType(Args::Type::Wait));
args.push_back(ForType(Args::Type::OpenLogs));
args.push_back(ForType(Args::Type::OutputLocale));
args.push_back(ForType(Args::Type::OutputEncoding));
args.push_back(ForType(Args::Type::NoVT));
args.push_back(ForType(Args::Type::RainbowStyle));
args.push_back(ForType(Args::Type::RetroStyle));
Expand Down
Loading
Loading