Re: Using $?

Discussion in 'Perl' started by Jürgen Exner, Jul 11, 2003.

  1. Blueice wrote:
    > I have a Perl script which launches an executable file written in
    > Delphi. I am executing this Delphi file using backticks.
    >
    > The Delphi program returns a value 10 if it is able to complete
    > processing. If any exception occurs, it returns a value 20. This is
    > done using Halt(10); or Halt(20); at the appropriate place within the
    > Delphi program.
    >
    > When I display the value of $? in Perl, I receive 2560 (if processing
    > was completed successfully within the Delphi program) or 5120 (if an
    > exception error occurred). Am I using $? in the correct way, ie. to
    > identify if an external program was successfully executed? Can someone
    > kindly enlighten me on the significance of these numbers (2560, 5120)?


    Did you check The Fine Manual? From 'perldoc perlvar':
    $? [...]
    This is just the 16-bit status word returned
    by the wait() system call (or else is made up to look like it).
    Thus, the exit value of the subprocess is really ("$? >> 8"),
    and "$? & 127" gives which signal, if any, the process died
    from, and "$? & 128" reports whether there was a core dump.

    jue
     
    Jürgen Exner, Jul 11, 2003
    #1
    1. Advertising

  2. Blueice wrote:
    > "Jürgen Exner" <> wrote in message
    > news:<PJxPa.72453$>...
    >> Blueice wrote:
    >>> I have a Perl script which launches an executable file written in
    >>> Delphi. I am executing this Delphi file using backticks.
    >>>
    >>> The Delphi program returns a value 10 if it is able to complete
    >>> processing. If any exception occurs, it returns a value 20. This is
    >>> done using Halt(10); or Halt(20); at the appropriate place within
    >>> the Delphi program.
    >>>
    >>> When I display the value of $? in Perl, I receive 2560 (if
    >>> processing was completed successfully within the Delphi program) or
    >>> 5120 (if an exception error occurred). Am I using $? in the correct
    >>> way, ie. to identify if an external program was successfully
    >>> executed? Can someone kindly enlighten me on the significance of
    >>> these numbers (2560, 5120)?

    >>
    >> Did you check The Fine Manual? From 'perldoc perlvar':
    >> $? [...]
    >> This is just the 16-bit status word returned
    >> by the wait() system call (or else is made up to look
    >> like it). Thus, the exit value of the subprocess is
    >> really ("$? >> 8"), and "$? & 127" gives which signal,
    >> if any, the process died from, and "$? & 128" reports
    >> whether there was a core dump.

    >
    > Thanks for the clarification, so it means that I shouldn't be using $?
    > to check for the exit code, right?


    Did you actually read the excerpt from The Fine Manual?
    [...] Thus, the exit value of the subprocess is
    really ("$? >> 8"), [...]
    Isn't that what you are looking for?

    > I tried assigning the output of the backticks to a variable, but the
    > variable does not have any value.
    > ie.
    > $mydemo=`$demoprog $myoldfile $mynewfile 5`;


    Do you know what backticks do?

    > ($demoprog is the path of the executable to be run, the remaining 3
    > values are arguments needed for the executable)
    > When I attempt to print out the value of $mydemo, it is blank.


    Then I would guess that your program does not print anything to STDOUT.

    >Is
    > there any other way of getting the exitcode from the Delphi program?


    Maybe you are confusing backticks and system()? The return value of system
    contains exit value of the subprocess (in the same encoded form as $?,
    please see "perldoc -f system" for details).
    But the return value of backticks is the output of the subprocess.

    jue
     
    Jürgen Exner, Jul 12, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William F. Robertson, Jr.
    Replies:
    1
    Views:
    979
    Kathy Burke
    Jun 25, 2003
  2. pete
    Replies:
    1
    Views:
    2,945
    Jon Yates
    Aug 29, 2003
  3. timmso
    Replies:
    1
    Views:
    505
    Alex Papadimoulis
    Dec 12, 2003
  4. Replies:
    2
    Views:
    556
  5. =?Utf-8?B?R1REcml2ZXI=?=
    Replies:
    1
    Views:
    3,826
    Karl Seguin
    Feb 16, 2005
Loading...

Share This Page