Why don't scripting languages output Unicode to the Windows console?

前端 未结 9 1609
迷失自我
迷失自我 2020-12-08 11:18

The Windows console has been Unicode aware for at least a decade and perhaps as far back as Windows NT. However for some reason the major cross-platform scripting languages

9条回答
  •  悲哀的现实
    2020-12-08 11:32

    Small contribution to the discussion - I am running Czech localized Windows XP, which almost everywhere uses CP1250 code page. Funny thing with console is though that it still uses legacy DOS 852 code page.

    I was able to make very simple perl script that prints utf8 encoded data to console using:

    binmode STDOUT, ":utf8:encoding(cp852)";
    

    Tried various options (including utf16le), but only above settings printed accented Czech characters correctly.

    Edit: I played a little more with the problem and found Win32::Unicode. The module exports function printW that works properly both in output and redirected:

    use utf8;
    use Win32::Unicode;
    
    binmode STDOUT, ":utf8";
    printW "Příliš žluťoučký kůň úpěl ďábelské ódy";
    

提交回复
热议问题