Dru has asked for the wisdom of the Perl Monks concerning the following question:
Produces:use warnings; use strict; use Mail::Sender; use IO::Scalar; my $output; my $date = '31Jul200'; my $logfile = "d:\\log\\$date.log"; my $elogfile = "d:\\log\\exported\\$date.elog"; tie (*STDOUT, 'IO::Scalar', \$output); # Use this to capture STDOUT my $cmd = `fw logexport -i $logfile -o $elogfile -r 1000 -n`; untie *STDOUT; # Use this to return STDOUT to normal print "my output='$output'"
And using IO::Capture::Stdout:D:\scripts>perl temp.pl Failed to open file 'd:\log\31Jul200.log': The system cannot find the file specified. untie attempted while 1 inner references still exist at temp.pl line 14. Use of uninitialized value in concatenation (.) or string at temp.pl line 15. my output=''
Produces:use warnings; use strict; use IO::Capture::Stdout; my $capture = IO::Capture::Stdout->new(); my $date = '31Jul200'; my $logfile = "d:\\log\\$date.log"; my $elogfile = "d:\\log\\exported\\$date.elog"; $capture->start(); my $cmd = `fw logexport -i $logfile -o $elogfile -r 1000 -n`; $capture->stop(); my $line = $capture->read; print "$line";
Any ideas what I'm doing wrong?D:\scripts>perl temp.pl Failed to open file 'd:\log\31Jul200.log': The system cannot find the file specified. Error retreaving captured text in IO::Capture::Stdout at temp.pl line 16 Use of uninitialized value in string at temp.pl line 19.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Redirecting STDOUT to Variable - Not Having Much Luck
by Mr. Muskrat (Canon) on Aug 05, 2003 at 16:43 UTC | |
|
Re: Redirecting STDOUT to Variable - Not Having Much Luck
by bobn (Chaplain) on Aug 05, 2003 at 17:23 UTC | |
|
Re: Redirecting STDOUT to Variable - Not Having Much Luck
by dragonchild (Archbishop) on Aug 05, 2003 at 16:36 UTC |