perl-unicode

Unicode on Windows Console

2012-01-07 11:31:05
There's a WinAPI function that sets stdout to Unicode so you can
read Cyrillic and Greek characters in the cmd.exe console window:

          \,,,/
          (o o)
------oOOo-(_)-oOOo------
// http://msdn.microsoft.com/en-us/library/tw4k6df8.aspx - _setmode
// crt_setmodeunicode.c
// This program uses _setmode to change
// stdout to Unicode. Cyrillic and Ideographic
// characters will appear on the console (if
// your console font supports those character sets).

#include <fcntl.h>
#include <io.h>
#include <stdio.h>

int main(void) {
    _setmode(_fileno(stdout), _O_U16TEXT);
    wprintf(L"\x043a\x043e\x0448\x043a\x0430 \x65e5\x672c\x56fd\n");
    return 0;
}
-------------------------

Compile it and will print "кошка 日本国", so a Russian name and three
fancy ideograms. (The ideograms aren't supported by my font, but that
is an unrelated problem; and I can't read them anyway; still they look
nice.) My console codepage is just 1252, Western European.

Can I get the same feature in Perl? I left the codepage at 1252 (can be
changes using CHCP) and tried the following:

* binmode STDOUT, ':encoding(UTF-16LE)'
* binmode STDOUT, ':encoding(UTF-16BE)'
* binmode STDOUT, ':encoding(UTF-8)'

None of these produced the desired effect. Any ideas?

I know I could use a Linux UTF-8 terminal or Cygwin/MinTTY, which is
what I'm using to write this mail, by the way; but the question is
specific to the Windows console in cmd.exe and how to make Perl use
its features.
-- 
Michael Ludwig

<Prev in Thread] Current Thread [Next in Thread>