Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-03

Exit Status of Lazarus App

13 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

David Copeland

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.

Reply by email

Reinier Olislagers
to David Copeland
David Copeland wrote
Hi, 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...)

Reply by email

Mark Morgan Lloyd
to Reinier Olislagers
Reinier Olislagers wrote 10 lines
On 21-3-2013 14:23, David Copeland wrote: > Hi, > > 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.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Reinier Olislagers
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 17 lines
Reinier Olislagers wrote: > On 21-3-2013 14:23, David Copeland wrote: >> Hi, >> >> 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...

Reply by email

Sven Barth
to Mark Morgan Lloyd: If halt (with a parameter) is called, are there any bits of normal termination that get…
Mark Morgan Lloyd wrote 17 lines
Reinier Olislagers wrote: > On 21-3-2013 14:23, David Copeland wrote: >> Hi, >> >> 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.

"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

Reply by email

David Copeland
to Mark Morgan Lloyd: If halt (with a parameter) is called, are there any bits of normal termination that get…
Mark Morgan Lloyd wrote 17 lines
Reinier Olislagers wrote: > On 21-3-2013 14:23, David Copeland wrote: >> Hi, >> >> 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.

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.

Reply by email

David Copeland
to Sven Barth

Hi Sven,

Thank you very much!

Dave.

Sven Barth wrote 18 lines
Am 21.03.2013 14:23, schrieb David Copeland: > Hi, > > 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 -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Mark Morgan Lloyd
to Sven Barth: The variable you are looking for is called "ExitCode" (and as it is in unit System it's…
Sven Barth wrote 8 lines
Am 21.03.2013 14:23, schrieb David Copeland: > Hi, > > 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

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.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

David Copeland
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 15 lines
Sven Barth wrote: > Am 21.03.2013 14:23, schrieb David Copeland: >> Hi, >> >> 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 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.

Reply by email

Mark Morgan Lloyd
to David Copeland
David Copeland wrote
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.

Working from memory I think that's by design, it's the way the unix system calls work.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

waldo kitty
to David Copeland: As an aside, I have discovered that if you use FpSystem to run a Lazarus App, the exit…
David Copeland wrote
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.

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...

Reply by email

Sven Barth
to Mark Morgan Lloyd: Working from memory I think that's by design, it's the way the unix system calls work.…
Mark Morgan Lloyd wrote 10 lines
David Copeland wrote: > 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. 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

Reply by email