将 Unicode 字符打印到 PowerShell 提示符 [英] Printing Unicode characters to the PowerShell prompt

查看:20
本文介绍了将 Unicode 字符打印到 PowerShell 提示符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置 Mercurial 以打印出我当前使用 PowerShell 所在的存储库的状态.到目前为止,我一切正常,但我希望能够在我在存储库中时将☿"打印到提示中.不幸的是,PowerShell 在打印 Unicode 字符方面似乎存在一些问题.

I'm trying to set up Mercurial to print out the status of the repository I'm currently in with PowerShell. So far, I have everything working, but I would like to be able to print '☿' to the prompt when I am in a repository. Unfortunately, it seems that PowerShell has some problems with printing Unicode characters.

是否有可以显示 Unicode 字符的 Windows 命令外壳?建议 Windows 7(我正在使用)附带的 PowerShell v2 能够打印 Unicode 字符,但我似乎无法让它工作.同样,使用 chcp 65001 的下一个答案也不起作用.

In the accepted answer for Is there a Windows command shell that will display Unicode characters? it is suggested that PowerShell v2, which shipped with Windows 7 (which I am using) would be able to print Unicode characters, but I can't seem to get it to work. Likewise, the next answer of using chcp 65001 does not work either.

这仍然是 PowerShell 的不足,还是我遗漏了一些明显的东西?

Is this still a deficiency in PowerShell, or am I missing something obvious?

推荐答案

这不是 PowerShell 的缺陷.这是 PowerShell.exe 使用的 Windows 控制台子系统的一个缺陷.控制台子系统不支持 Unicode,而是支持可追溯到 DOS 时代的代码页.PowerShell V2 修复是通过 PowerShell 集成脚本环境或 PowerShell_ISE.exe 提供的.这是一个基于 WPF 的图形化应用程序,可以轻松处理 Unicode 字符.

This is not a PowerShell deficiency. It is a deficiency with the Windows console subsystem which PowerShell.exe uses. The console subsystem does not support Unicode but code pages instead which dates back to the DOS days. The PowerShell V2 fix is provided via the PowerShell Integrated Scripting Environment or PowerShell_ISE.exe. This is a graphical app based on WPF which can handle Unicode characters easily.

理论上您可以使用 chcp 或

In theory you could change the code page using chcp or

[Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding(850)

显示不同的字符,但我对此不太走运.您还需要找到包含要显示的字符的代码页.

to display different characters but I haven't had much luck with this. You'd also need to find a code page that contains the character you want to display.

这篇关于将 Unicode 字符打印到 PowerShell 提示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆