Hi,
How can I set the exit status/return code of a Lazarus application? I have done some searching but haven't found it.
Thanks,
Dave Copeland.

Mailing lists / lazarus / 2013-03
13 messages · 5 people ·
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi,
How can I set the exit status/return code of a Lazarus application? I have done some searching but haven't found it.
Thanks,
Dave Copeland.
David Copeland wroteHi, How can I set the exit status/return code of a Lazarus application? I have done some searching but haven't found it.
IIRC, I think it's halt.
There might be a fancy lazarus way of doing it (have a look at the application object...)
If halt (with a parameter) is called, are there any bits of normal termination that get skipped? I use it during startup if there's some obvious problem (e.g. a socket can't be created) but I was wondering a few days ago how best to set a result during routine shutdown.
AFAIR (again) the docs say halt just unceremoniously exits, skipping any application finalization etc.
That's why I suspect the application object may have some property that sets the exit code or some such...
If halt (with a parameter) is called, are there any bits of normal termination that get…
"Halt" executes the same termination that happens when you leave the main procedure (and it does not matter whether you call "Halt(param)" or "Halt", because the latter simply does a "Halt(0)").
Regards,
Sven
If halt (with a parameter) is called, are there any bits of normal termination that get…
I was worried about that also, like freeing memory. I believe that the IDE itself can return a "restart" status to startlazarus, but I can't find it.
How can I set the exit status/return code of a Lazarus application? I have done some…
David Copeland wroteHi, How can I set the exit status/return code of a Lazarus application? I have done some searching but haven't found it.
The variable you are looking for is called "ExitCode" (and as it is in unit System it's always available). See here:
http://www.freepascal.org/docs-html/rtl/system/exitcode.html
Regards,
Sven
Hi Sven,
Thank you very much!
Dave.
The variable you are looking for is called "ExitCode" (and as it is in unit System it's…
Thanks for that as well. I've experimentally put it in a signal handler (that otherwise has the effect of setting a flag which is checked at an opportune point in the code) and can confirm it works. Also OK in an OnCloseQuery handler etc.
As an aside, I have discovered that if you use FpSystem to run a Lazarus App, the exit code returned is multiplied by 256 (or mishandled somehow), Eg. 1 => 256, 13 => 3328, etc. However when run using TProcess the exit code is returned correctly.
Dave.
David Copeland wroteAs an aside, I have discovered that if you use FpSystem to run a Lazarus App, the exit code returned is multiplied by 256 (or mishandled somehow), Eg. 1 => 256, 13 => 3328, etc. However when run using TProcess the exit code is returned correctly.
Working from memory I think that's by design, it's the way the unix system calls work.
As an aside, I have discovered that if you use FpSystem to run a Lazarus App, the exit…
David Copeland wroteAs an aside, I have discovered that if you use FpSystem to run a Lazarus App, the exit code returned is multiplied by 256 (or mishandled somehow), Eg. 1 => 256, 13 => 3328, etc. However when run using TProcess the exit code is returned correctly.
check the code for FpSystem and you might find that it has its own exit codes in the 0 thru 255 range... to keep the two processes from interfering with each other, one takes the lower and the other's are incremented by 256... i've seen this used in numerous places... i have even implemented it in years past... the hardest part is remembering which set of 256 belongs to what set of code...
Working from memory I think that's by design, it's the way the unix system calls work.…
According to the man page you are right. The man page of "system" refers to "5 wait" regarding the exitstatus which mentions that you should use the macro "WEXITSTATUS(status)" to get the exitcode which will return (according to its implementation) return the upper 8 bits of the status (which is a 16 bit value).
Regards,
Sven