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{}.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|