12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package SimplyGit::Shellex;
- use strict;
- use warnings;
- use Log::Log4perl qw(:easy);
- use Exporter qw(import);
- our @EXPORT_OK = qw(shellex findBin);
- sub shellex {
- my $cmd = shift;
- my $logger = shift;
- if ( defined $logger && $logger ne '' ) {
- $logger->info("Running: $cmd 2>&1");
- }
- my $output = `$cmd 2>&1`;
- my $rc = $?;
- if ( defined $logger && $logger ne '' ) {
- $logger->info("Returned: $rc");
- }
- if ( $rc != 0 ) {
- if ( defined $logger && $logger ne '' ) {
- $logger->error("$cmd returned non-zero: $rc");
- }
- print "$cmd returned non-zero: $rc, exiting\n";
- exit 1;
- }
- return $output;
- }
- sub findBin {
- my $cmd = shift;
- my $logger = shift;
- my $binPath = shellex("which $cmd",$logger);
- my $rc = $?;
- chomp $binPath;
- if ( $rc != 0 ) {
- if ( defined $logger && $logger ne '' ) {
- $logger->error("Couldn't find a path for $cmd, exiting...");
- }
- exit 1;
- } else {
- return $binPath;
- }
- }
- 1;
|