Difference between revisions of "Returning exit code"
m (1 revision) |
m (Link to language startup.) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 48: | Line 48: | ||
== See Also == | == See Also == | ||
− | The [http://mdfs.net/blib ProgEnv] library provides an <code>exit()</code> function to exit the program setting the exit code, and return to any calling program. | + | * The [http://mdfs.net/blib ProgEnv] library provides an <code>exit()</code> function to exit the program setting the exit code, and return to any calling program. |
+ | * [[Passing a parameter to a language]] | ||
[[User:Jgharston|Jgharston]] 10:56, 30 April 2008 (BST) | [[User:Jgharston|Jgharston]] 10:56, 30 April 2008 (BST) |
Latest revision as of 23:50, 30 June 2018
A program can return an exit code by setting the user byte with OSBYTE &01. The calling program can then read the exit code. Depending on the called program, the calling program may be returned to at the calling point, or it may be re-run. Consequently, the calling program needs to read the exit code both when it starts and immediately after calling another program.
The value &0 should be returned for no error occured. If the called program does not know about exit codes, and never calls OSBYTE 01, then the calling program will cleanly receive a no error code.
Contents
BASIC code
Calling program:
at program startup... exit%=FNbyte(1,0,0) ... when calling external command... OSCLI command$ exit%=FNbyte(1,0,0) ... when calling external BASIC program... CHAIN program$ REM exit code will be read when this program is re-run
Called program:
at program exit: OSCLI "FX1,"+STR$exit% IF ASCquit$=42:OSCLI quit$ ELSE IF quit$<>"":CHAIN quit$
6502 code
Calling program:
LDX #cmd AND 255 LDY #cmd DIV 256 :\ Point to program to call JSR OS_CLI :\ Run program LDA #1:LDX #0:JSR OSBYTE :\ Read exit code
Called program finishes with:
LDX #exit_code LDA #1:JMP OSBYTE :\ Set exit code and return
C code
Calling program:
exitcode=system(program);
Called program finishes with:
exit(exitcode);
See Also
- The ProgEnv library provides an
exit()
function to exit the program setting the exit code, and return to any calling program. - Passing a parameter to a language
Jgharston 10:56, 30 April 2008 (BST)