1

I'm trying to write a small Log::Any::Adapter for Wx logging, and for testing I'm using Wx's LogStderr class. My test fails, though, because the string printed to STDERR has every other character as a NULL. I figure that it's probably UTF-16le since I'm on Windows. I know I can do

decode('UTF-16le', $_)

but is there a way I can determine the encoding so the code works on all systems?

My attempt:

use strict;
use warnings;
use Test::More tests => 1;
use Wx;
use Capture::Tiny qw(capture_stderr);
use Encode::Locale;
use Encode qw(decode);
Wx::Log::SetActiveTarget(Wx::LogStderr->new());
my $stderr = capture_stderr { Wx::LogMessage('hello!') };
$stderr = decode(console_in => $stderr); #doesn't work; still has NUL's
like($stderr, qr/hello!/, 'Wx logs correctly to STDERR');

I'd paste the output, but with all of the NULs I can't get it to copy onto my clipboard!

ikegami
  • 367,544
  • 15
  • 269
  • 518
Nate Glenn
  • 6,455
  • 8
  • 52
  • 95
  • (There's always `$^O`) – ikegami Sep 13 '13 at 23:58
  • @ikegami Thanks for the edits. Do all of the other platforms print in a way that I wouldn't need `decode` at all? – Nate Glenn Sep 14 '13 at 00:07
  • Looking at the [`Encode::Locale` source code](http://cpansearch.perl.org/src/GAAS/Encode-Locale-1.03/lib/Encode/Locale.pm) it seems that a number of methods are tried to get the right encoding on Windows systems. Some methods are using optional modules (`Win32::Console`, `Win32::API`). Probably it helps if you look with a debugger what's going on here. – Slaven Rezic Sep 14 '13 at 15:04

0 Answers0