Loading ...
Sorry, an error occurred while loading the content.

system() call in END() subroutine overrides script exit value

Expand Messages
  • Kelly Jones
    ... Mon May 17 11:09:43 MDT 2010 0 In other words, the return value of the date command in an END subroutine overrides my desired exit value. How do I fix
    Message 1 of 2 , May 17 10:54 AM
    • 0 Attachment
      I did this in tcsh:

      > perl -le 'exit(2); sub END {system("date");}' ; echo $status
      Mon May 17 11:09:43 MDT 2010
      0

      In other words, the return value of the date command in an END subroutine
      overrides my desired exit value.

      How do I fix this? I want to tell Perl: if I explicitly do exit($foo), I
      want the script to exit with status $foo?

      --
      We're just a Bunch Of Regular Guys, a collective group that's trying
      to understand and assimilate technology. We feel that resistance to
      new ideas and technology is unwise and ultimately futile.
    • merlyn@stonehenge.com
      ... Kelly Mon May 17 11:09:43 MDT 2010 Kelly 0 Kelly In other words, the return value of the date command in an END subroutine Kelly overrides my desired
      Message 2 of 2 , May 17 11:18 AM
      • 0 Attachment
        >>>>> "Kelly" == Kelly Jones <kelly.terry.jones@...> writes:

        Kelly> I did this in tcsh:
        >> perl -le 'exit(2); sub END {system("date");}' ; echo $status
        Kelly> Mon May 17 11:09:43 MDT 2010
        Kelly> 0

        Kelly> In other words, the return value of the date command in an END subroutine
        Kelly> overrides my desired exit value.

        Kelly> How do I fix this? I want to tell Perl: if I explicitly do exit($foo), I
        Kelly> want the script to exit with status $foo?

        Add "local $?" to the beginning of your END block. Then, nothing within
        that block can affect your exit status.

        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
        See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
      Your message has been successfully submitted and would be delivered to recipients shortly.