Page 1 of 1

END [exitcode] -- reading the program exit or error code

Posted: Sun Oct 09, 2016 12:39 am
by Keya
cos i couldnt find an existing example and was wondering

EXITWITHCODE.PB - PB app that exits with an error code

Code: Select all

#ERRCODE = 123
OpenConsole()
PrintN("Exiting with error code " + Str(#ERRCODE))
End #ERRCODE
The following three demos simply execute the above app and read/display its error code...

GETEXITCODE.PB - PB app that runs a program and reads its error code

Code: Select all

OpenConsole()
hRunApp = RunProgram("exitcode.exe", "", "", #PB_Program_Wait | #PB_Program_Open)
PrintN("The program exited with code " + Str(ProgramExitCode(hRunApp))): Input()
GETEXITCODE.BAT - Windows batch file that runs a program and reads its error code

Code: Select all

exitcode.exe
@echo The program exited with code %errorlevel%
GETEXITCODE.SH - Linux & Mac bash script that runs a program and reads its error code

Code: Select all

#!/bin/bash
./exitcode
echo "The program exited with code $?"

Re: END [exitcode] -- reading the program exit or error code

Posted: Sun Oct 09, 2016 7:42 am
by netmaestro
The 'exit code' can actually be used for one more (afaik undocumented) use, which I hope will prove self-explanatory:

Code: Select all

Procedure Cleanup()
  Debug "Cleaning up this"
  Debug "cleaning up that"
EndProcedure

Debug "Main Loop..."

End Cleanup()