Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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,

Comment on How to determine of script executed correctly?
Download Code
Re: How to determine of script executed correctly?
by choroba (Abbot) 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 (Vicar) on Apr 20, 2012 at 21:36 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://966261]
Approved by davies
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (16)
As of 2014-07-30 16:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (236 votes), past polls