Merge branch 'JABAWS_Release_2_5' into develop
[jabaws.git] / binaries / src / jpred / lib / Run.pm
diff --git a/binaries/src/jpred/lib/Run.pm b/binaries/src/jpred/lib/Run.pm
new file mode 100644 (file)
index 0000000..6bc6a78
--- /dev/null
@@ -0,0 +1,33 @@
+package Run;
+
+use strict;
+use warnings;
+use Carp;
+
+use Exporter;
+use POSIX qw(WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG);
+
+our @ISA = qw(Exporter);
+our @EXPORT_OK = qw(check);
+
+sub check {
+       my ($prog, $status) = @_;
+
+       if ($status == 0) {
+               return 1;
+       }
+       elsif ($status == -1) {
+               croak "$prog executable not found\n";
+       }
+       elsif (WIFEXITED($status) and WEXITSTATUS($status)) {
+               croak "$prog exited with status ".WEXITSTATUS($status)."\n";
+       }
+       elsif (WIFSIGNALED($status)) {
+               croak "$prog halted by external signal ".WTERMSIG($status)."\n";
+       }
+       else {
+               croak "$prog suffered from a random pantwetting event";
+       }
+}
+
+1;