![]() |
|
|
|
#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 |
|
|
|
|
#2 |
|
Posts: n/a
|
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 |
|