How to redirect/capture debug information to variable ?

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
arv
Posts: 4
Joined: 2013-05-23T07:34:08-07:00
Authentication code: 6789

How to redirect/capture debug information to variable ?

Post by arv » 2014-04-22T14:53:37-07:00

Hello,

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:
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'
How to do it?

Regards,
arv

Post Reply