WinNT/2k/XP uses Unicode. The "console" window has Unicode versions and Code-Page versions of the various input and output functions. Perl supports Unicode. All should be well, right?

Well, first of all the default STDOUT behavior seems to truncate characters to 8 bits and warn if the ordinal was >255, NOT do a encoding translation to the current character set.

If the "current" set of 256 characters (the Code Page) is enough and I don't worry about UTF-8, the results in the Console don't match what appears in the source. That's because the Windows Code Page is 1252, but for compatibility with old text-mode code from DOS, the Console uses the old DOS code page by default.

So, I use the commands

chcp 1252 mode con cp select=1252
at the prompt, expecting it will not match the rest of the machine.

Nope! The results of programs running standard output, or the type command, etc. are still showing the DOS characters.

Anybody know the right incantation to make the Windows Console use the desired code page in this manner?

Better yet, is there a way to make Perl's output use the full Unicode capability of the Console? I'm thinking that a tie'd handle could feed to the Win32 API functions, skipping the OS's file stream.

Best of all, is there a way to make the OS's stream (that's attached to the Console) use UTF-8? That would work with any program, not just Perl.

—John


In reply to Character Encoding and Windows Console woes by John M. Dlugosz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.