Here is a fully-working example on how to write Unicode text to the console under Windows with Perl 5.8 / 5.10:

http://sourceforge.net/projects/filereadtest/

The script also works under Cygwin and Linux, only the standard Perl console output is used instead.

If anyone wants to factor out the relevant code into a CPAN Perl module with the usual licences, I would welcome it. Unfortunately, I haven't got the necessary experience to do it myself.

I few months ago I tried to find some source code or information here in perlmonks.org and in CPAN, but I couldn't find anything ready-made and directly useful. But maybe I've just missed something.

Thanks,
R. Diez

Replies are listed 'Best First'.
Re: Unicode console output under Windows
by Anonymous Monk on Oct 04, 2009 at 10:32 UTC
    Ouch. I'm no win32 expert, but it looks like there is too much conversion in that program
    #!/usr/bin/perl -- use strict; use warnings; binmode STDOUT, ':encoding(UTF-8)'; my( $chcp ) = (`chcp`) =~ /(\d+)/; $chcp and qx!chcp 65001!; #now UTF-8 print "Hello, printing chr 900..950\n"; $|=1; for(900..950){ print $_, ' ',chr($_), ' '; print "\n" if 0 == $_ % 6; } $chcp and `chcp $chcp`; # restore original __END__
      I don't think changing the console's codepage is a good idea. If your script aborts or gets killed before restoring the codepage, the console will remain in UTF-8 mode for any other applications to come. And that's assuming nobody else is using the same console while your script is running.
      R. Diez