Go Back   Velocity Reviews > Newsgroups > PERL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

PERL - Re: Using $?

 
Thread Tools Search this Thread
Old 07-11-2003, 01:05 PM   #1
Default Re: Using $?


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
  Reply With Quote
Old 07-12-2003, 03:46 AM   #2
Jürgen Exner
 
Posts: n/a
Default Re: Using $?

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


  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump