General discussion

Locked

Ret err code from 32bit code - DOS batch

By dvenardos ·
How do your return an error code to a Dos batch file from 32bit C code that makes a call to the windows API? When calling a 32bit console app from a batch file, the batch file executes the program and continues instead of waiting for the return code. If you use cscript.exe to run script code, however, the batch file will wait for the return code, so there must be a way to compile the C code that allows DOS to receive the return value.

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Valentino In reply to Ret err code from 32bit c ...

Don't know if you still need help, but...
Every program returns some code. Usually programs return zero on success and >0 on error. To check which code a program returned in batch file you should use "if errorlevel NNN" command.
First of all, there are three ways of starting a program in a batch file:
------------------------------------------------
rem This line starts the program and waits for it to terminate
SomeProgram.exe

rem This line starts the program and also waits for it to terminate
start /wait SomeProgram.exe

rem This line starts the program and DOESN'T wait for it to terminate
start SomeProgram.exe
------------------------------------------------

Now how you can check the return code:

------------------------------------------------
if not errorlevel 1 goto NoError

echo Some error occurred!
goto Finish

:NoError
echo OK, no error!

:Finish
------------------------------------------------

Or this way:

------------------------------------------------
if errorlevel 1 goto GotError

echo OK, no error!
goto Finish

:GotError
echo Some error occurred!

:Finish
------------------------------------------------

This is under WinNT 4.0. There might be some differences under other operating systems.

Back to Windows Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums