Restored from previous forum. Originally posted by horst.
Is there any way to set the exit code for a PB program?
(like with the API function TerminateProcess)
Horst
[Implemented] ExitCode
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by MrVainSCL.
Hi horst
I am not sure if i understand you correct!? You want a way to exit/close your program/application if you or the user want it?
If so... just use the PB-Command "End" and the program will exit..
Btw i am not sure if you mean this...
PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...
greetz
MrVainSCL! aka Thorsten
Hi horst
I am not sure if i understand you correct!? You want a way to exit/close your program/application if you or the user want it?
If so... just use the PB-Command "End" and the program will exit..
Btw i am not sure if you mean this...
PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...
greetz
MrVainSCL! aka Thorsten
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by horst.
child has to say. It is passed to the OS with the termination of a program.
For example the IF ERRORLEVEL test in a batch (DOS or CMD.EXE)
uses this exit code.
Horst
No, the exit code can be tested by the parent process to find out what theYou want a way to exit/close your program/application if you or the user want it?
child has to say. It is passed to the OS with the termination of a program.
For example the IF ERRORLEVEL test in a batch (DOS or CMD.EXE)
uses this exit code.
Horst
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Insomniac.
I'm using ExitProcess_ successfully for this. i.e.
ExitProcess_(ReturnCode)
However, could one of you more more experienced folk confirm if this prevents PB from doing it's housekeeping such as closure of files and releasing memory etc.
Currently I make sure I do these things in my code BEFORE calling exitprocess_.
Insomniac - Registered PB User
I'm using ExitProcess_ successfully for this. i.e.
ExitProcess_(ReturnCode)
However, could one of you more more experienced folk confirm if this prevents PB from doing it's housekeeping such as closure of files and releasing memory etc.
Currently I make sure I do these things in my code BEFORE calling exitprocess_.
Insomniac - Registered PB User
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by horst.
> .... if this prevents PB from doing it's housekeeping
> such as closure of files and releasing memory etc.
That's what I'm also afraid of...
The API doc says:
> Terminating a process does not necessarily remove the process object
> from the operating system. A process object is deleted when the last
> handle to the process is closed.
.. but I don't know what exactly that means for a PB program.
A new SetExitCode(code.b) function or an alternative End(code.b)
would be a clean solution.
PureBasic could be such a nice language to write batch tools...
Fred?
Horst
> .... if this prevents PB from doing it's housekeeping
> such as closure of files and releasing memory etc.
That's what I'm also afraid of...
The API doc says:
> Terminating a process does not necessarily remove the process object
> from the operating system. A process object is deleted when the last
> handle to the process is closed.
.. but I don't know what exactly that means for a PB program.
A new SetExitCode(code.b) function or an alternative End(code.b)
would be a clean solution.
PureBasic could be such a nice language to write batch tools...
Fred?
Horst
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fred.
No problem, I will add it. End [ExitCode]. As you said, PB will clean all the opened libraries before quit, which is really needed and use TerminateProcess_() isn't a good alternative.. New Window versions tends to close all the stuffs itself, even if the coder doesn't do it (for stability reason) but previous one like win9x can be damaged and become unstable quickly.
Fred - AlphaSND
No problem, I will add it. End [ExitCode]. As you said, PB will clean all the opened libraries before quit, which is really needed and use TerminateProcess_() isn't a good alternative.. New Window versions tends to close all the stuffs itself, even if the coder doesn't do it (for stability reason) but previous one like win9x can be damaged and become unstable quickly.
Fred - AlphaSND
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by horst.
> ..I will add it. End [ExitCode]...
Thanks, Fred!
I have just tested ExitProcess_(ReturnCode) as suggested
by Insomniac, but this did not work. In a batch file
the Errorlevel is always zero.
However, when I use the command
START /W test.exe
it works nicely (Win98), and the correct Errorlevel is set.
I have no idea what's going on there
, but I guess (hope)
it will work when the ExitCode is properly integrated into PB.
Horst
> ..I will add it. End [ExitCode]...
Thanks, Fred!
I have just tested ExitProcess_(ReturnCode) as suggested
by Insomniac, but this did not work. In a batch file
the Errorlevel is always zero.
However, when I use the command
START /W test.exe
it works nicely (Win98), and the correct Errorlevel is set.
I have no idea what's going on there

it will work when the ExitCode is properly integrated into PB.
Horst
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Insomniac.
Can any of the people familiar with FASM help out with the code for this one?
The end of program code normally looks like this:
;
; End Of Program
;
PUSH dword [PB_MemoryBase]
CALL _HeapDestroy@4
PUSH dword 0
CALL _ExitProcess@4
_PB_EndFunctions:
RET
;
I just need a way of subsituting a value from a PB variable in place of the zero value in the final PUSH.
I'm not sure if the HeapDestroy removes all the PB variables, but if it does then the required variable would need to be stored somewhere safe (a register?) first.
Insomniac - Registered PB User
Can any of the people familiar with FASM help out with the code for this one?
The end of program code normally looks like this:
;
; End Of Program
;
PUSH dword [PB_MemoryBase]
CALL _HeapDestroy@4
PUSH dword 0
CALL _ExitProcess@4
_PB_EndFunctions:
RET
;
I just need a way of subsituting a value from a PB variable in place of the zero value in the final PUSH.
I'm not sure if the HeapDestroy removes all the PB variables, but if it does then the required variable would need to be stored somewhere safe (a register?) first.
Insomniac - Registered PB User