in reply to Capturing both STDOUT, STDERR and exit status

Heres an example. You can also use select on the filehandles.
#!/usr/bin/perl use warnings; use strict; use IPC::Open3; my $cmd = 'ls -la'; my $pid = open3(\*WRITER, \*READER, \*ERROR, $cmd); #if \*ERROR is 0, stderr goes to stdout while( my $output = <READER> ) { print "output->$output"; } while( my $errout = <ERROR> ) { print "err->$errout"; } waitpid( $pid, 0 ) or die "$!\n"; my $retval = $?; print "retval-> $retval\n";

I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^2: Capturing both STDOUT, STDERR and exit status
by greenmoss (Novice) on Jun 02, 2010 at 19:03 UTC
    (hopefully not being too much of a thread necrophile here) This is an excellent example, which has just saved me from abhorrent temp file hell. One small quibble; the retval line should probably read:
    my $retval = $? >> 8;