perlsen has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

How to return the exit status to command prompt after execution of perl script?.
I need to store the last return value 0 or 1. To pass this input to the next program.
it would be useful if you give some suggestions regarding this.

Thanks
perlsen
  • Comment on How to return the exit status thru perl script execution?

Replies are listed 'Best First'.
Re: How to return the exit status thru perl script execution?
by Corion (Patriarch) on Feb 15, 2006 at 08:02 UTC

    Have you looked at the documentation of the exit function? It does just that, allow you to pass a specific exit code. Another possibility would be to die in your program, but that will not allow you to specify a number and always exit with 255 (see die).

      Thanks Corion,
      I have resolved the problem.
      regards,
      Perlsen
Re: How to return the exit status thru perl script execution?
by vennirajan (Friar) on Feb 15, 2006 at 09:05 UTC
    You can use the exit function to return the value to the parent process. From the parent environment you can also get the return status. If you are using the *nix , you can fetch the exit status of the previous process by printing the env variable $?.
     Hope the below example will help you!

    #!/usr/bin/perl -w use strict; print "This is going to exit\n"; exit 2;

    $> perl aboveProgram.pl This is going to exit $> echo $? 2 $>


    Regards,
    S.Venni Rajan.
    "A Flair For Excellence."
                    -- BK Systems.
Re: How to return the exit status thru perl script execution?
by idle (Friar) on Feb 15, 2006 at 08:59 UTC
    ... if($success){$status_code = 0} else{$status_code = 1} exit($status_code)