Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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
Replies are listed 'Best First'.
Re: How to determine of script executed correctly?
by choroba (Canon) 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 about the Monastery: (8)
As of 2015-07-29 11:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls