I would like to redirect/capture information about corrupted data to a variable in Perl.
My code doesn't work, the variable $output is empty:
Code: Select all
my $output;
close STDERR;
open( STDERR, ">", \$output ) or die "Error: $!\n";
my $image = Image::Magick->new;
$image->Set( debug => 'Exception' );
my $res = $image->Read( 'file.jpg' );
print $output;
When I turn off redirect STDERR to a variable my program prints on the console what I want capture:
How to do it?2014-04-22T16:51:44+02:00 0:00.092 0.094u 6.8.9 Exception perl.exe[93288]: jpeg.c/JPEGWarningHandler/351/Exception
Corrupt JPEG data: premature end of data segment `file.jpg'
2014-04-22T16:51:44+02:00 0:00.101 0.094u 6.8.9 Exception perl.exe[93288]: jpeg.c/JPEGWarningHandler/351/Exception
Corrupt JPEG data: 5 extraneous bytes before marker 0xd5 `file.jpg'
Regards,
arv