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{}.
In reply to Re: Capture external program return value
by tokpela
in thread Capture external program return value
by llancet
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |