IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 10, 2026, 3:41:52 PM (6 weeks ago)
Author:
eugene
Message:

add ps_run to Config.pm

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-pstamp-20260421/PS-IPP-Config/lib/PS/IPP/Config.pm

    r42832 r43051  
    4646                    caturi
    4747                    file_scheme
     48                    ps_run
    4849                    );
    4950our %EXPORT_TAGS = (standard => [@EXPORT_OK]);
     
    17541755}
    17551756
     1757sub ps_run {
     1758
     1759    my %args = @_;
     1760
     1761    unless (exists $args{command}) { carp "Missing command argument in ps_run\n"; }
     1762    my $command = $args{command};
     1763
     1764    my $verbose = 0;
     1765    if (exists $args{verbose}) { $verbose = $args{verbose}; }
     1766
     1767    # print "command: $command\n";
     1768
     1769    my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     1770
     1771    ## upon success, we can just return
     1772    if (defined $success && $success) {
     1773        my $error_code = 0;
     1774        return ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf);
     1775    }
     1776
     1777    my $error_code = 0;
     1778
     1779    ## old-style IPC::Cmd returns an error code in the second argument:
     1780    if ($IPC::Cmd::VERSION < 0.40) {
     1781        $error_code = $error_msg;
     1782    } else {
     1783        if (defined $error_msg) {
     1784            if ($error_msg =~ /exited with value (\d+)/) {
     1785                $error_code = $1 << 8;
     1786            } elsif ($error_msg =~ /died with signal (\d+)/) {
     1787                $error_code = $1;            # signal in low byte, same as waitpid
     1788            } elsif ($error_msg =~ /open3: exec/) {
     1789                $error_code = 0x200;        # missing executable
     1790            } else {
     1791                $error_code = 0x400;        # unknown failure (
     1792            }
     1793        } else {
     1794            $error_code = 0x800;        # unknown failure
     1795        }
     1796    }
     1797    return ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf);
     1798}
     1799
     1800# this is a basic utility to support both old and new versions of IPC::Cmd run
     1801# if the program exited normally, the exit value is returned
     1802# if the program exited with a signal (abort, crash, etc), PS_EXIT_PROG_ERROR (4) is returned
     1803# if the program failed to run, -PS_EXIT_PROG_ERROR (-4) is returned
     1804sub parse_error_message_alt {
     1805    my $success = shift;
     1806    my $error_msg = shift;
     1807    my $command = shift;
     1808
     1809    if ($success) { return 0; }
     1810
     1811    print "raw error_msg: $error_msg\n";
     1812    print "full command: $command\n";
     1813
     1814    if (&looks_like_number($error_msg)) { return (($error_msg >> 8) or ($PS_EXIT_PROG_ERROR)); }
     1815       
     1816    # which of these match?
     1817    my ($error_code) = $error_msg =~ m/exited with value (\d+)/;
     1818    if (defined $error_code) { return $error_code; }
     1819   
     1820    ($error_code) = $error_msg =~ m/died with signal (\d+)/;
     1821#   if (defined $error_code) { return (128 + $error_code); }
     1822    if (defined $error_code) { return ($PS_EXIT_PROG_ERROR); }
     1823   
     1824    # probably failed to execute:
     1825    return (-1*$PS_EXIT_PROG_ERROR);
     1826}
    17561827
    175718281;
Note: See TracChangeset for help on using the changeset viewer.