Index: /branches/eam_branches/ipp-20230313/ippScripts/scripts/xcsky.pl
===================================================================
--- /branches/eam_branches/ipp-20230313/ippScripts/scripts/xcsky.pl	(revision 42579)
+++ /branches/eam_branches/ipp-20230313/ippScripts/scripts/xcsky.pl	(revision 42580)
@@ -18,4 +18,5 @@
 
 use IPC::Cmd 0.36 qw( can_run run );
+use Scalar::Util qw(looks_like_number);
 use PS::IPP::Metadata::Config;
 use PS::IPP::Metadata::List qw( parse_md_list );
@@ -113,9 +114,8 @@
     my $command = "$xcskytool -inputs -xcsky_id $xcsky_id";
     $command .= " -dbname $dbname" if defined $dbname;
-    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => $command, verbose => $verbose);
+    my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
+    my $error_code = &parse_error_message ($success, $error_msg, $command);
     unless ($success) {
-        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-        &my_die("Unable to perform xcskytool -inputs: $error_code", $xcsky_id, $error_code);
+        &my_die("Unable to perform $command: $error_msg", $xcsky_id, $error_code);
     }
 
@@ -268,10 +268,9 @@
 
             unless ($no_op) {
-                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
-		print "error code: $error_code\n";
-                unless ($success) {
-                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-                    &my_die("Unable to perform psphotStack: $error_code", $xcsky_id, $error_code);
-                }
+                my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
+		my $error_code = &parse_error_message ($success, $error_msg, $command);
+		unless ($success) {
+                    &my_die("Unable to perform psphotStack: $error_msg", $xcsky_id, $error_code);
+		}
 
                 # my $outputStatsReal = $ipprc->file_resolve($outputStats);
@@ -353,16 +352,12 @@
         }
 
-        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-            run(command => $command, verbose => $verbose);
-        unless ($success) {
-	    print "error: $error_code\n";
-            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-            my $err_message = "Unable to perform: $command\n";
-            warn($err_message);
+        my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
+	my $error_code = &parse_error_message ($success, $error_msg, $command);
+	unless ($success) {
+            warn("Unable to perform: $command\n");
             exit $error_code;
         }
     }
 }
-
 
 sub my_die
@@ -392,4 +387,31 @@
 }
 
+# if the program exited normally, the exit value is returned
+# if the program exited with a signal (abort, crash, etc), PS_EXIT_PROG_ERROR (4) is returned
+# if the program failed to run, -PS_EXIT_PROG_ERROR (-4) is returned
+sub parse_error_message {
+    my $success = shift;
+    my $error_msg = shift;
+    my $command = shift;
+
+    if ($success) { return 0; }
+
+    print "raw error_msg: $error_msg\n";
+    print "full command: $command\n";
+
+    if (&looks_like_number($error_msg)) { return (($error_msg >> 8) or ($PS_EXIT_PROG_ERROR)); }
+	
+    # which of these match?
+    my ($error_code) = $error_msg =~ m/exited with value (\d+)/;
+    if (defined $error_code) { return $error_code; }
+    
+    ($error_code) = $error_msg =~ m/died with signal (\d+)/;
+#   if (defined $error_code) { return (128 + $error_code); }
+    if (defined $error_code) { return ($PS_EXIT_PROG_ERROR); }
+    
+    # probably failed to execute:
+    return (-1*$PS_EXIT_PROG_ERROR);
+}
+
 END {
     my $exit = $?;
