Index: /branches/eam_branches/ipp-pstamp-20260421/pstamp/scripts/pstamp_finish.pl
===================================================================
--- /branches/eam_branches/ipp-pstamp-20260421/pstamp/scripts/pstamp_finish.pl	(revision 43022)
+++ /branches/eam_branches/ipp-pstamp-20260421/pstamp/scripts/pstamp_finish.pl	(revision 43023)
@@ -137,6 +137,6 @@
             $command   .= " -dbname $dbname" if $dbname;
             $command   .= " -dbserver $dbserver" if $dbserver;
-            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) {
                 die("Unable to perform $command error code: $error_code");
@@ -260,9 +260,9 @@
         {
             my $command = "$pstamp_results --input $table_def_name --output $outdir/results.fits";
-            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) {
                 print STDERR "Unable to perform $command error code: $error_code\n";
-                $request_fault = $error_code >> 8;
+                $request_fault = $error_code;
             } else {
                 # dump a textual representation
@@ -271,5 +271,5 @@
                     run(command => $command, verbose => $verbose);
                 unless ($success) {
-                    $request_fault = $error_code >> 8;
+                    $request_fault = $error_code;
                     my_die("Unable to perform $command error code: $error_code", $req_id, $request_fault);
                 }
@@ -288,5 +288,5 @@
             run(command => $command, verbose => $verbose);
         unless ($success) {
-            $request_fault = $error_code >> 8;
+            $request_fault = $error_code;
             my_die("Unable to perform $command error code: $error_code\n", $req_id, $request_fault);
         }
@@ -505,2 +505,29 @@
     return 40587.0 + ($ticks/86400.);
 }
+
+# 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);
+}
