Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
No such thing as a small change
 
PerlMonks  

Interpret $? variable

by rbala (Acolyte)
on Sep 12, 2013 at 09:40 UTC ( #1053686=perlquestion: print w/ replies, xml ) Need Help??
rbala has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, When a process is successful I see the value stored in this variable is 0. But , if unsucessful, the value is undeterministic and for various commands, I get different outputs. But I just need to check if the command is successful or not. My doubt is, can i confirm that if $? is 0 , then the command is successful ? Thanks, Bala.

Comment on Interpret $? variable
Re: Interpret $? variable
by daxim (Chaplain) on Sep 12, 2013 at 09:50 UTC
    Yes, that's the convention. I recommend IPC::System::Simple which has a very convenient API for this use-case.

    use IPC::System::Simple qw(runx); runx [0], 'some_command', @more_arguments;
Re: Interpret $? variable
by mtmcc (Hermit) on Sep 12, 2013 at 09:51 UTC
    It depends on the command.

    Have a look at this. I hope it's helpful.

      Thank you
Re: Interpret $? variable
by Marshall (Prior) on Sep 13, 2013 at 06:36 UTC
    Yes,
    The return value of "zero" usually means success.

    Something other than "0" usually means "Oops -
    problem with an error code".

    The error code is deterministic, but depends upon
    the error codes for that subroutine.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (14)
As of 2014-04-24 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (565 votes), past polls