日文汉字和表情符号字符在新的Windows终端(从微软商店安装)的Powershell窗口中显示为?(问号),在CMD窗口中可以正确显示日文和中文字符而表情符号字符仍然不能。
微软声称新的 Windows 终端很好地支持 utf8 字符,但为什么会发生这种情况呢?是否有任何选项可以打开 utf8 支持?
操作系统版本:10.0.19042
日文汉字和表情符号字符在新的Windows终端(从微软商店安装)的Powershell窗口中显示为?(问号),在CMD窗口中可以正确显示日文和中文字符而表情符号字符仍然不能。
微软声称新的 Windows 终端很好地支持 utf8 字符,但为什么会发生这种情况呢?是否有任何选项可以打开 utf8 支持?
操作系统版本:10.0.19042
正如@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 中正确处理代理对)。