rvosa has asked for the wisdom of the Perl Monks concerning the following question:
However, things seem to get stuck in the while loop. What am I doing wrong? What's the canonical way to capture STDERR (I know, I know, TMTOWTDI so I may not need the canonical way, just one that works).use IO::Handle; my @logmessages; my $stderr = IO::Handle->new; $stderr->autoflush( 1 ); $stderr->fdopen( fileno( STDERR ), 'r' ); system( 'command', 'with', 'args' ); while( defined( my $line = $stderr->getline ) ) { push @logmessages, $line; } $stderr->close; # now do something useful with @logmessages
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Capturing STDERR using IO::Handle
by ikegami (Patriarch) on Nov 26, 2007 at 09:28 UTC | |
by xdg (Monsignor) on Nov 26, 2007 at 21:31 UTC | |
|
Re: Capturing STDERR using IO::Handle
by ysth (Canon) on Nov 26, 2007 at 09:11 UTC | |
|
Re: Capturing STDERR using IO::Handle
by phio (Acolyte) on Nov 26, 2007 at 11:44 UTC | |
|
Re: Capturing STDERR using IO::Handle
by educated_foo (Vicar) on Nov 26, 2007 at 14:04 UTC | |
by ikegami (Patriarch) on Nov 26, 2007 at 17:14 UTC | |
by educated_foo (Vicar) on Nov 26, 2007 at 18:10 UTC | |
by xdg (Monsignor) on Nov 26, 2007 at 21:39 UTC | |
by ikegami (Patriarch) on Nov 26, 2007 at 18:19 UTC | |
by educated_foo (Vicar) on Nov 26, 2007 at 21:00 UTC | |
| |
|
Re: Capturing STDERR using IO::Handle
by DrHyde (Prior) on Nov 26, 2007 at 11:44 UTC | |
by salva (Canon) on Nov 26, 2007 at 11:56 UTC | |
|
Re: Capturing STDERR using IO::Handle
by Sidhekin (Priest) on Nov 26, 2007 at 15:48 UTC |