Printing Unicode characters to the PowerShell prompt

22,688

Solution 1

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.

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.

Solution 2

Prints semi-fine here. Consolas doesn't have a glyph for that character, so all I see in the console window is a replacement glyph. But PowerShell accepts and prints it just fine, as you can see when copy-pasting it.

Now, if you have set your console window to raster fonts, then the story is a little different, but PowerShell luckily has sane defaults.

Solution 3

You can't using the default PowerShell (i.e. windows) console. However, if you use the PowerShell ISE (which provides its own console), it will work. I am not sure if this will meet your needs though.

Solution 4

Deja Vu Sans Mono works in cmd and has that character, and so it works in PowerShell too.

Enter image description here

Enter image description here

BTW, I suggest also installing Droid Sans Mono, and Courier New, to the command prompt. They'll then be available in PowerShell too. There aren't many mono spaced fonts that cmd supports. But those are three, Deja Sans Mono, Droid Sans Mono, and Courier New.

Solution 5

You need to

  1. install a monospace font in your system, that contains your glyph (possibly use Character Map to find a suitable one, etc) and then
  2. set it as a console font, as described here: http://www.watchingthenet.com/how-to-add-and-change-fonts-in-windows-command-prompt.html
Share:
22,688

Related videos on Youtube

tghw
Author by

tghw

I am a freelance developer based in Denver, CO. Previously, I was a developer at Fog Creek Software, where I helped create Copilot, Kiln, WebPutty, and Trello.

Updated on July 09, 2022

Comments

  • tghw
    tghw almost 2 years

    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.

    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.

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

    • JPBlanc
      JPBlanc about 13 years
      Can you give a hard copy of what you want to prompt, or the unicode code you want to prompt with a table with their representation ?
  • Rich
    Rich about 13 years
    The console supports Unicode, there just isn't much rendering support. No font substitution, no complex script rendering, etc. And well, with Raster fonts you're back in the DOS days, but PowerShell luckily uses a TrueType font as default.
  • barlop
    barlop almost 9 years
    @Joey you say it supports unicode, but in what way does it support unicode more than cmd did? chcp 1200 fails chcp 1201 fails. so the 16bit unicode codepages aren't supported. You can do chcp 65001 but apparently that's buggy and many batch files and C programs crash with it. And it's UTF-8 without BOM. Notepad can't create a file in UTF-8 without BOM. type manages to read a UTF-16 LE w BOM file even with codepage 65001 (which is UTF-8 without BOM). I agree it can work with unicode to an extent, but the support seems to be the same as cmd had.
  • barlop
    barlop almost 9 years
    character map won't help finding a font to install on a system, because that only shows fonts on your system. babelmap will scan all fonts on your system but still only fonts on your system.. If a font is already on your system then fine.. But I don't think one is that has that glyph. A long while back I looked into what fonts I could install on cmd prompt, I ran into 3.. one was Deja Vu Sans Mono, and that has his character. See my answer.
  • Eryk Sun
    Eryk Sun over 6 years
    The console has limited rendering of the full Unicode range since it's not using Uniscribe or DirectWrite. But that's unrelated to CMD, which is a Unicode application. The main problem is CMD doesn't support UTF BOMs to set the encoding of a batch script or piped output in a for /f loop. Instead it relies on the console's legacy codepage, which you can set via chcp.com. Using codepage 65001 (UTF-8) can be buggy for legacy console applications (e.g. python.exe prior to 3.6), so you should change it only temporarily for select lines in a script (e.g. to read a block of environment variables).
  • Eryk Sun
    Eryk Sun over 6 years
    I'm surprised by how many people blame the shell for problems in legacy console applications. Programs don't run in the shell, and I'd hope a moment's reflection and inspection of the process list would lead one to understand that consoles and terminals are a separate resource from shells. Anyway, Since Mercurial is a Python application, I assume once it's using Python 3.6+ it will no longer default to using the console's legacy codepage API. It took us in the Python development community way too long to fix this. I think the issue lingered for a decade.