PowerShell / PowerShell/vscode-powershell

Integrated Console only sets Console.OutputEncoding to UTF-8, not also Console.InputEncoding

Open
#2,816 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area-Extension Terminal Issue-Bug
Dominant language
TypeScript
Stars
1.9k
Forks
547
PR merge metrics
No merged PRs in 30d

Description

System Details

System Details Output

### VSCode version: 1.47.2 17299e413d5590b14ab0340ea477cdd86ff13daf x64

### VSCode extensions:
DavidAnson.vscode-markdownlint@0.36.1
fabianlauer.vs-code-xml-format@0.1.5
florianloch.text-transform@0.1.0
formulahendry.code-runner@0.11.0
idleberg.applescript@0.18.2
ms-azure-devops.azure-pipelines@1.170.0
ms-dotnettools.csharp@1.22.1
ms-python.python@2020.7.94776
ms-vscode.azure-account@0.8.11
ms-vscode.cpptools@0.29.0
ms-vscode.powershell@2020.6.0
Shan.code-settings-sync@3.4.3
slevesque.vscode-autohotkey@0.2.2
slevesque.vscode-hexdump@1.7.2
twxs.cmake@0.0.17
vitaliymaz.vscode-svg-previewer@0.5.2


### PSES version: 2.2.0.0

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      7.1.0-preview.5
PSEdition                      Core
GitCommitId                    7.1.0-preview.5
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Issue Description

Unlike regular console windows (and unlike PowerShell running as a regular shell in the VSCode integrated terminal), the PowerShell Integrated Console sets [console]::OutputEncoding to UTF-8, which causes output from external programs to be interpreted as UTF-8-encoded.

However, it doesn't also set the input encoding, [console]::InputEncoding, which not only makes sense for consistency, but has unwanted side effects:

PowerShell [Core] v6+ itself also defaults to UTF-8 in the $OutputEncoding preference variable, which means that text sent to external programs is sent as UTF-8.

However, not setting [console]::InputEncoding means that external programs that run the chcp utility to infer the active OEM code page still see the system's OEM code page - this could affect how Visual Studio Code's code CLI interprets its stdin input - see https://github.com/PowerShell/PowerShell/issues/13216

Setting [console]::InputEncoding causes chcp to reflect the newly assigned encoding's code page (but note that using chcp itself to change the code page from inside PowerShell doesn't work, because .NET caches the [console] encodings).

Expected Behaviour
PS> chcp
65001  # UTF-8
Actual Behaviour
PS> chcp
437  # e.g., on US-English systems

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

No file or test is named. Locate the Integrated Console setup that assigns Console.OutputEncoding and inspect how console encodings are initialized. Done means the console input encoding is also UTF-8 and running chcp in the Integrated Console reports code page 65001, without changing encoding via chcp itself.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell, typescript
Domain
cli, developer-experience
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.