Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

How to determine of script executed correctly?

by julio_514 (Acolyte)
on Apr 20, 2012 at 21:14 UTC ( #966261=perlquestion: print w/replies, xml ) Need Help??
julio_514 has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks, I'm writing a Perl pipeline which consists of a script executing other scripts (Perl and non-Perl). My question: Say I have scriptA. ScriptA executed well and returns valueX that will act as input of scriptB. But suppose, there was a problem in the execution of scriptA and it did not return valueX, what would be the best way (command) to make my pipeline die? I tried:
system($scriptA); #? == -1 ? die "Command failed: $!\n" : print "Command executed succes +sfuly\n";
This line works fine if I called a command that does not exists (script will die), but I believe that proceeding this way do not make the script die if the command is found and called but not executed because of wrong/absent arguments...? Thanks,

Replies are listed 'Best First'.
Re: How to determine of script executed correctly?
by choroba (Bishop) on Apr 20, 2012 at 21:31 UTC
    You probably mean $? instead of #?. If you want your script to die on any error, use rather
    if ($? != 0) { die "Command failed: $!"; } else { print "Command executed successfuly.\n"; }
    But it really depends on the command itself and what exit status it returns in various situations.
      Yeah my bad it is indeed $?. Ok thanks, seems to work fine!
Re: How to determine of script executed correctly?
by davies (Parson) on Apr 20, 2012 at 21:36 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://966261]
Approved by davies
NodeReaper recites The Raven over the P.A. again

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2018-03-21 22:55 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (272 votes). Check out past polls.