On Wed, Jun 13, 2001 at 11:53:48AM -0400, Charles Lu wrote:
> How do I direct the messages destined for STDERR and redirect them to 
> STDOUT?
> 
> 
> 
> I have a perl script A that calls another program B.  If there is bad input, 
> Program B dumps out a lot of error messages through STDERR.  I want to be 
> able to stop my perl script when it detects messages coming from program B.  
> What is the best way to do that?  One way I thought of is by redirecting 
> error messages to STDOUT and capture it in my perl program and TERMINATE the 
> perl program if it detects anything.  (when program B runs normally, there 
> is no output)

Well, if you're on a Unix(-like) system, you can redirect STDOUT on the
command line:

$return = `program_B 2>&1`;
if ($return) {die "Program B blew up.\n"};

Not sure whether something like the following would work or not.

open PROGRAM_B, "program_B 2>&1 |";


I'm sure others will have more elegant solutions.

chrs
rob c

Reply via email to