Commit de8ff48f authored by Matthieu Muffato's avatar Matthieu Muffato
Browse files

Use Tiny::Capture to run the command in SystemCmd

It allows to capture stderr, and output a more useful message when the command fails.
parent a39d84f3
......@@ -2,3 +2,4 @@ requires 'DBI';
requires 'DBD::mysql';
requires 'DBD::SQLite';
requires 'JSON';
requires 'Capture::Tiny';
......@@ -61,6 +61,9 @@ package Bio::EnsEMBL::Hive::RunnableDB::SystemCmd;
use strict;
use warnings;
use Capture::Tiny ':all';
use base ('Bio::EnsEMBL::Hive::Process');
......@@ -122,13 +125,16 @@ sub run {
}
$self->dbc and $self->dbc->disconnect_when_inactive(1); # release this connection for the duration of system() call
my $return_value;
my $stderr = tee_stderr {
system(ref($cmd) ? @$cmd : $cmd);
$return_value = $? >> 8;
};
$self->dbc and $self->dbc->disconnect_when_inactive(0); # allow the worker to keep the connection open again
if(my $return_value = system(ref($cmd) ? @$cmd : $cmd)) {
$return_value >>= 8;
die "system( $flat_cmd ) failed: $return_value";
if($return_value) {
die sprintf( "'%s' resulted in an error code=%d\nstderr is: %s\n", $flat_cmd, $return_value, $stderr);
}
$self->dbc and $self->dbc->disconnect_when_inactive(0); # allow the worker to keep the connection open again
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment