10

On Windows 7, dir or tree can't show unicode characters, even starting cmd with cmd /U

So I would press Window Key + R to run something, and type in cmd /U so that the content might handle Unicode.

And then using dir or tree /F, the content in Unicode won't show as Unicode. (in Window Explorer (file manager), the Unicode will show)

Is there a way to handle it? To get Unicode characters to test your filenames, you can go to

http://news.google.com/news?edchanged=1&ned=tw

and you will be able to get many Unicode characters there (UTF-8)

4
  • Have you tried this with Powershell yet? Windows 7 has it installed by default.
    – KdgDev
    Jun 27, 2010 at 1:25
  • If I use PowerShell, and do a help ls -full it doesn't have such option as cmd's dir /B Jun 27, 2010 at 5:03
  • Remember, PowerShell pipes objects between commands - you can get behavior similar to dir /b by executing: dir | % { $_.Name }
    – Goyuix
    Nov 18, 2010 at 14:27
  • @Guyuix: Or gci | select -expand Name
    – Joey
    Apr 10, 2011 at 8:32

4 Answers 4

9

Change the font for the console window to a TrueType font, such as Lucida Console or Consolas. With raster fonts you are restricted to the OEm character set.

cmd /u only changes output piped into files, not what you see on screen.

PowerShell by default uses a TrueType font which is why it worked for you.

This has nothing to do with cmd.

6
  • 1
    Even if I change to Lucida or Consolas and run cmd /u, I don't get the Unicode characters.
    – Snark
    Apr 10, 2011 at 8:07
  • 2
    If you see boxes, then it does indeed work. The console subsystem does not support font switching so it can only use glyphs from the single font you specified. And since neither font has glyphs for Han ideographs you'll see only boxes. However, the text is there; you can copy and paste it, for example. You won't see anything different in PowerShell, though, unless you use the PowerShell ISE (which is not a console application and therefore not subject to the same limitations).
    – Joey
    Apr 10, 2011 at 8:31
  • 1
    @Joey The problem is entirely a result of using CMD. CMD cannot display Unicode characters. CMD can display DBCS characters, but only that of your system locale. Change your system locale to Shift-JIS, reboot, and you'll be able to show Japanese (Shift-JIS only, not Unicode) characters. The CMD command line processor supports Unicode, thus you can pipe output to files and open them in Notepad, for example, but you can't display Unicode.
    – Jeff
    Dec 2, 2014 at 3:09
  • 1
    @Jeff it can't display a lot characters simply because those characters aren't exist in the current font. It can't simply replace the characters by the same in another font like in GUI, as the font policy in cmd is very strict, it only accepts some specific fixed-width font. It isn't because of locale because if I set the codepage to Vietnamese, cmd can still display Russian, Turkish, Japanese... characters without problem, provided that the characters are available in the font.
    – phuclv
    Dec 2, 2014 at 7:51
  • This is not really true that This has nothing to do with cmd. When I use dir /s into console, unicode characters are showed correctly, whilst when I pipe them into file, they are messed. Only chcp 65001 solves the problem.
    – Suncatcher
    May 29, 2018 at 12:41
1

https://stackoverflow.com/questions/10764920/utf-16-on-cmd-exe

  1. Open/run cmd.exe
  2. Click on the icon at the top-left corner
  3. Select properties
  4. Then Font bar
  5. Select Lucida Console and OK.
  6. Write Chcp 10000 at the prompt
  7. Finally dir /b

Also from https://stackoverflow.com/questions/379240/is-there-a-windows-command-shell-that-will-display-unicode-characters/24135341#24135341

  1. CHCP 65001
  2. DIR > UTF8.TXT
  3. TYPE UTF8.TXT
3
  • 10000 is not a Unicode codepage and it can only displays characters in Mac Roman charset
    – phuclv
    Jun 10, 2014 at 9:58
  • how can you display like, Chinese, Japanese characters or emoticons... in that codepage?
    – phuclv
    Jun 10, 2014 at 10:01
  • For Japanese you can do chcp 932. But this uses Shift-JIS so the emoticons or Chinese won't work.
    – Tensigh
    Nov 11, 2016 at 6:23
0

It's not just a command prompt problem, but a Windows problem in general. The C "wide-character" functions in Windows (namely wprintf) do not support Unicode.

12
  • Proof for your claim? MSDN constantly mentions the wide-char variants for Unicode.
    – Joey
    Apr 10, 2011 at 8:34
  • 1
    Here's one.
    – user541686
    Apr 10, 2011 at 8:37
  • you are aware that that is a bug that was reported on a prerelease version of Visual Studio 2005 and has been long fixed (not to mention that we're at VS 2010 by now ...)? Note also that the Windows API can easily be used and there is no particular reason to use the C standard library in places where no portability problems are likely to be encountered.
    – Joey
    Apr 10, 2011 at 20:18
  • @Joey: No, I wasn't aware of that. However, right now I'm using Visual Studio 2008 and calling wprintf(L"私"), and it's definitely not printing anything Unicode. Do you have any example of complex scripts that do get printed with wprintf? (Locale changing shouldn't be needed because the strings are UTF-16.)
    – user541686
    Apr 10, 2011 at 20:24
  • 1
    The Windows console does support Unicode because it uses Unicode behind the scenes stackoverflow.com/questions/1259084/… stackoverflow.com/questions/2213541/… stackoverflow.com/questions/388490/… In Windows 7 codepage 65001 can't display the characters correctly but you can copy the them to a text editor to see the correct output. In Windows 8 it displays UTF-8 without problem
    – phuclv
    Jun 10, 2014 at 9:56
0

Reg file

Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Console] "CodePage"=dword:fde9

Command Prompt

REG ADD HKCU\Console /v CodePage /t REG_DWORD /d 0xfde9

PowerShell

sp -t d HKCU:\Console CodePage 0xfde9

Cygwin

regtool set /user/Console/CodePage 0xfde9

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .