in reply to Pipe, fork, exec and red-hot pokers.
use Carp; use IO::Handle; use IPC::Open3; use strict; my $STDOUT = IO::Handle->new; my $STDERR = IO::Handle->new; open($STDOUT, ">&STDOUT") || croak( 'Cannot duplicate STDOUT to file handle - ', $! ); open($STDERR, ">&STDERR") || croak( 'Cannot duplicate STDERR to file handle - ', $! ); eval { open3( '<&STDIN', $STDOUT, $STDERR, "some_application" ) || die $!; waitpid(-1, 0); }; croak( 'Cannot execute command - ', $@ ) if $@; # The STDOUT and STDERR output of some_application # execution now resides in $STDOUT and $STDERR # respectively. eg. print $_ foreach <$STDOUT>
As always with Perl, TMTOWTDI.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Pipe, fork, exec and red-hot pokers.
by hagus (Monk) on Apr 09, 2002 at 00:56 UTC | |
by rob_au (Abbot) on Apr 09, 2002 at 01:06 UTC | |
by hagus (Monk) on Apr 09, 2002 at 01:11 UTC | |
by rob_au (Abbot) on Apr 09, 2002 at 02:45 UTC |