I found that text going to STDOUT was correctly UTF8 encoded, but text going to STDERR wasn't.
You need to add the :utf8 layer to STDERR separately. As far as I can see, there is no way of combining layers with redirection in the same open statement. Instead, you need to use binmode on STDERR after redirecting it to STDOUT.
#!/usr/bin/perl use strict; use warnings; my $utf8="\xe9"; close (STDOUT); open( STDOUT, ">>:utf8", 'test.txt' ) or die $!; close STDERR; open( STDERR, ">>&STDOUT" ) or die $!; print ("STDOUT: ",$utf8,"\n"); print STDERR ("STDERR: ",$utf8,"\n"); binmode (STDERR,':utf8'); print STDERR ("STDERR with binmode: ",$utf8,"\n"); PRINTS: STDOUT: é STDERR: \xe9 (not literally - prints character \xe9, no +t UTF-8 encoded) STDERR with binmode: é
Clint
(thanks to tye and Joost for helping me figure this out)
Update: Filed as bug 44701
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Redirecting STDERR to STDOUT with UTF8 layer
by clinton (Priest) on Aug 16, 2007 at 12:39 UTC |