Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Capturing both STDOUT, STDERR and exit status

by zentara (Archbishop)
on May 06, 2005 at 16:40 UTC ( [id://454726]=note: print w/replies, xml ) Need Help??


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;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://454726]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-04-25 02:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found