Index: /trunk/ippScripts/scripts/register_imfile.pl
===================================================================
--- /trunk/ippScripts/scripts/register_imfile.pl	(revision 21933)
+++ /trunk/ippScripts/scripts/register_imfile.pl	(revision 21934)
@@ -17,9 +17,8 @@
 use Storable qw(freeze thaw);
 use File::Basename qw( basename);
-use IPC::Cmd 0.36 qw( can_run run );
+use IPC::Run qw( harness run );
 use PS::IPP::Config 1.01 qw( :standard );
 use PS::IPP::Metadata::Config;
-
-my $PI = 3.141592653589793238462643383279502;
+use Math::Trig;
 
 my $ipprc = PS::IPP::Config->new(); # IPP configuration
@@ -58,7 +57,11 @@
 # Look for programs we need
 my $missing_tools;
-my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1);
-my $ppStats = can_run('ppStats') or (warn "Can't find ppStats" and $missing_tools = 1);
-my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+my $regtool = `which regtool` or (warn "Can't find regtool" and $missing_tools = 1);
+my $ppStats = `which ppStats` or (warn "Can't find ppStats" and $missing_tools = 1);
+my $ppStatsFromMetadata = `which ppStatsFromMetadata` or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+chomp $regtool;
+chomp $ppStats;
+chomp $ppStatsFromMetadata;
+
 
 if ($missing_tools) {
@@ -80,16 +83,30 @@
 # Run ppStats on the input file
 {
-    my $command = "$ppStats $uri -recipe PPSTATS $RECIPE -level | $ppStatsFromMetadata - - REGISTER_IMFILE"; # Command to run ppStats and ppStatsFromMetadata
-    $command .= " -dbname $dbname" if defined $dbname;
-    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        cache_run(command => $command, verbose => $verbose);
-    unless ($success) {
-        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-        &my_die ("Unable to perform ppStats on exposure id $exp_id: $error_code", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $error_code);
-    }
-    foreach my $line (@$stdout_buf) {
-	$cmdflags .= " $line";
-    }
-    chomp $cmdflags;
+    my $command1 = "$ppStats $uri -recipe PPSTATS $RECIPE -level";
+    my $command2 = "$ppStatsFromMetadata - - REGISTER_IMFILE";
+
+    # Since there are no spaces in the arguments, we can get away with this:
+    my @command1 = split(/ /, $command1);
+    my @command2 = split(/ /, $command2);
+
+    # Run ppStats
+    my ($in1, $out1, $err1);    # Buffers for ppStats
+    my $h1 = harness \@command1, \$in1, \$out1, \$err1;
+    print "[Running $command1]\n";
+    my $result1 = run $h1;
+    print $out1;
+    print $err1;
+    &my_die("Unable to perform ppStats on exposure id $exp_id: " . $h1->result(), $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $h1->result() ) unless $result1;
+
+    print "[Running " . join(' ', @command2) . "]\n";
+    my ($out2, $err2);          # Buffers for ppStatsFromMetadata
+    my $h2 = harness \@command2, \$out1, \$out2, \$err2;
+    print "[Running $command2]\n";
+    my $result2 = run $h2;
+    print $out2;
+    print $err2;
+    &my_die("Unable to perform ppStatsFromMetadata on exposure id $exp_id: " . $h2->result(), $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $h2->result() ) unless $result2;
+    chomp $out2;
+    $cmdflags = $out2;
 }
 
@@ -123,9 +140,9 @@
 # if the needed data is available, pass it to sunmoon:
 if ($longitude && $latitude && $ra && $dec && $dateobs) {
-    
-    $longitude *= 12.0 / $PI; # longitude is reported in West radians; sunmoon wants it in West Hours
-    $latitude *= 180.0 / $PI; # latitude is reported in North radians; sunmoon wants it in North Degrees
-    $ra *= 180.0 / $PI; # ra is reported in radians; sunmoon wants it in degrees
-    $dec *= 180.0 / $PI; # dec is reported in radians; sunmoon wants it in degrees
+
+    $longitude *= 12.0 / pi; # longitude is reported in West radians; sunmoon wants it in West Hours
+    $latitude *= 180.0 / pi; # latitude is reported in North radians; sunmoon wants it in North Degrees
+    $ra *= 180.0 / pi; # ra is reported in radians; sunmoon wants it in degrees
+    $dec *= 180.0 / pi; # dec is reported in radians; sunmoon wants it in degrees
 
     my $sunmoon_cmd = "sunmoon -latitude $latitude -longitude $longitude -elevation $elevation $dateobs $ra $dec";
@@ -137,7 +154,7 @@
 
     if ($?) {
-	warn ("failure running $sunmoon_cmd, not supplying\n");
+        warn ("failure running $sunmoon_cmd, not supplying\n");
     } else {
-	$command .= " $sunmoon_data";
+        $command .= " $sunmoon_data";
     }
 }
