简体   繁体   English

UTF-8 字符在新 Windows 终端的 Powershell 中显示为问号

[英]UTF-8 characters displayed as question mark in the Powershell of new Windows Terminal

Japanese characters and Chinese characters, as well as emoji characters, are shown as?(question marks) in the Powershell window of the new Windows Terminal(installed from the Microsoft Store), and the Japanese and Chinese characters can be correctly shown in CMD window while the emoji characters still can not. Japanese characters and Chinese characters, as well as emoji characters, are shown as?(question marks) in the Powershell window of the new Windows Terminal(installed from the Microsoft Store), and the Japanese and Chinese characters can be correctly shown in CMD window而表情符号字符仍然不能。

Microsoft claims that the new Windows Terminal supports the utf8 characters well but why can this happen?微软声称新的 Windows 终端很好地支持 utf8 字符,但为什么会发生这种情况? Are there any options to turn on the utf8 support?是否有任何选项可以打开 utf8 支持?

OS version: 10.0.19042操作系统版本:10.0.19042

As @vonPryz said, the Windows Terminal itself supports Unicode characters.正如@vonPryz 所说,Windows 终端本身支持 Unicode 字符。 If you want to handle Japanese characters in PowerShell, you have to change the codepage of your console to 932 .如果要在 PowerShell 中处理日文字符,则必须将控制台的代码页更改为932

Note that when you change the codepage of the console, first you have to run cmd.exe from PowerShell, then change the codepage in your console with chcp , and run powershell.exe .请注意,当您更改控制台的代码页时,首先您必须从 PowerShell 运行cmd.exe ,然后使用chcp更改控制台中的代码页,然后运行powershell.exe If you run chcp directly from PowerShell, it shows Japanese characters as ?如果您直接从 PowerShell 运行chcp ,它将显示日文字符为? . .

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\> cmd
Microsoft Windows [Version 10.0.19041.985]
(c) Microsoft Corporation. All rights reserved.

C:\>chcp 932 & powershell

(Whole screen is cleared)

現在のコード ページ: 932
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

新しいクロスプラットフォームの PowerShell をお試しください https://aka.ms/pscore6

PS C:\> Write-Host "日本語"
日本語

在此处输入图像描述

You can handle Japanese AND Chinese characters with chcp 65001 .您可以使用chcp 65001处理日文和中文字符。

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\> cmd
Microsoft Windows [Version 10.0.19041.985]
(c) Microsoft Corporation. All rights reserved.

C:\>chcp 65001 & powershell
Active code page: 65001
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\> Write-Host "日本語"
日本語
PS C:\> Write-Host "汉语"
汉语

在此处输入图像描述

Also, note that powershell.exe cannot handle emoji characters and causes System.Text.EncoderFallbackException in codepage 65001 because it uses surrogate-pair ( powershell.exe cannot handle surrogate pair correctly in codepage 65001).另外,请注意powershell.exe无法处理表情符号字符并导致代码页 65001 中的System.Text.EncoderFallbackException因为它使用代理对( powershell.exe无法在代码页 65001 中正确处理代理对)。

  • Windows Terminal version: 1.7.1033.0 Windows 终端版本:1.7.1033.0
  • OS Version: Windows 10 Version 2004 (Build 19401.985)操作系统版本:Windows 10 版本 2004(内部版本 19401.985)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM