in reply to Capture external program return value
IPC::Run3 will allow you to capture the output as well as the return code from the program you are running.
Untested late night code ;-)
use strict; use warnings; use IPC::Run3; my ($in, $out, $err); my @cmd = qw{blastall -i foo -o bar -p blastx -d baz}; eval { run3 \@cmd, \$in, \$out, \$err); } if ($@) { die "[Error] Command encountered an error in IPC::Run3 [$@]\n"; } if ($?) { die "[Error] Command encountered an error [$?]\n"; }
From the docs...
run3 throws an exception if the wrapped system call returned -1 or anything went wrong with run3's processing of filehandles. Otherwise it returns true. It leaves $? intact for inspection of exit and wait status.
Note that a true return value from run3 doesn't mean that the command had a successful exit code. Hence you should always check $?.
Updated with Perlbotics and Hue-Bond suggested use of qw{}.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Capture external program return value
by Hue-Bond (Priest) on May 02, 2010 at 08:23 UTC |