i have something i have been trying to get to work in windows for the past almost 3 weeks. ive searched many places and cant seem to find an answer.

how do i input unicode characters into a perl command-line program (using "cmd.exe") and have the character(s) printed back to the console properly?

i have tried using the perl "-C" switch to "tell" perl how to expect command line input, but it does not work. i have tried setting the "binmode", and "encode"/"decode"-ing. i input characters either by using the windows "character map" or using "alt+####" (for example alt+2190 for a left arrow). when i try to output the character it will print a "?" (question mark), which i understand the reason for this is because it does not know how to represent this character or understand it.

in cmd.exe i have used "chcp 65001" to set the encoding to UTF-8, and changed the font to "Lucida Console".

if i write a perl script to output a hardcoded unicode character (ie "\x{2190}") it does not print properly to the screen, however if i write it to a file or redirect the output to a file, it appears perfectly in the file. for example if i were to run the following: print "(\x{2190})";it would appear, in the console, as something like: ")<left arrow printed properly here>)" notice the first open parenthesis is printed as a close parenthesis. this happens if it is any character, not just parenthesis (of course). there seems to be some confusion on cmd.exe's part, as you can see the last character is printed either 2 times or overwrites the first character.

using the same perl script in linux (ie "konsole") works, and, as stated above, the script works when output is to a file. this likely means that it is a cmd.exe problem and not perl. i think a similar solution is necessary to allow unicode input in windows too.

thanks for any help


In reply to Unicode input in windows xp (cmd.exe) by nadroj

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.