run_cmd && utf8 streams

Darin McBride darin.mcbride at shaw.ca
Fri Jul 6 02:45:34 CEST 2012


Is there a recommended way to run commands that might output utf8 streams 
(e.g., Japanese)?

Here is a rough example of what I'm trying to do:

#!/bin/env perl5.10.1

use 5.10.1;
use utf8;
use AnyEvent;
use AnyEvent::Util;

binmode STDOUT, ':utf8';

if (@ARGV)
{
    say "これは日本語です";
    exit 0;
}    

my $stdout = '';
sub run
{
    my $cv = AnyEvent::Util::run_cmd [ $^X, $0, 1 ],
        '>' => \$stdout;
    $cv->recv();
}

run();
print $stdout;

__END__

Except that in the real code, I'm not running myself, I'm running an arbitrary 
system command whose source I have no control over.  I'm not sure if I can get 
in there to add the :encoding(UTF-8) / :utf8 layer to the pipe that my parent 
process has created.  At least, I'm not sure there's a supported method of 
doing this.

Is there a way to do this?  If not, would that be considered for the future?

Thanks,



More information about the anyevent mailing list