Duncan Bayne has asked for the wisdom of the Perl Monks concerning the following question:
Hi All,
I'm trying to execute a command-line program called myprogram that, upon failure, writes some text to STDERR. What I'd like to do is open a pipe to that program, and capture the output from STDERR. Something like this:
$Result = ""; open($ResultPipe, "./myprogram |"); while ( <$ResultPipe> ) { $Result = "$Result$_"; } close($ResultPipe);
Of course, this doesn't work - it captures STDOUT from myprogram instead of STDERR. I could just redirect STDERR output to a temporary file, but I'm trying to avoid temporary files and associated nastiness.
Any help would be greatly appreciated :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Capturing STDERR with a pipe
by graff (Chancellor) on Aug 20, 2002 at 05:12 UTC | |
|
Re: Capturing STDERR with a pipe
by kshepherd (Initiate) on Aug 20, 2002 at 05:02 UTC | |
|
(jeffa) Re: Capturing STDERR with a pipe
by jeffa (Bishop) on Aug 20, 2002 at 03:24 UTC |