0

日文汉字和表情符号字符在新的Windows终端(从微软商店安装)的Powershell窗口中显示为?(问号),在CMD窗口中可以正确显示日文和中文字符而表情符号字符仍然不能。

微软声称新的 Windows 终端很好地支持 utf8 字符,但为什么会发生这种情况呢?是否有任何选项可以打开 utf8 支持?

操作系统版本:10.0.19042

4

1 回答 1

1

正如@vonPryz 所说,Windows 终端本身支持 Unicode 字符。如果要在 PowerShell 中处理日文字符,则必须将控制台的代码页更改为932.

请注意,当您更改控制台的代码页时,首先您必须cmd.exe从 PowerShell 运行,然后使用 更改控制台中的代码页chcp,然后运行powershell.exe​​. 如果chcp直接从 PowerShell 运行,它会将日文字符显示为?.

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 "日本語"
日本語

在此处输入图像描述

您可以使用 处理日文和中文字符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 "汉语"
汉语

在此处输入图像描述

另外,请注意powershell.exe无法处理代码页 65001 中的表情符号字符和原因System.Text.EncoderFallbackException,因为它使用代理对(powershell.exe无法在代码页 65001 中正确处理代理对)。

  • Windows 终端版本:1.7.1033.0
  • 操作系统版本:Windows 10 版本 2004(内部版本 19401.985)
于 2021-05-24T15:54:07.307 回答