Computing.Net > Forums > Disk Operating System > error return by a prog

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

error return by a prog

Reply to Message Icon

Name: nico
Date: June 16, 2000 at 05:12:19 Pacific
Comment:

Hi,

Does anyone know if (and how) it is possible
to retrieve the error code of a program with
a dos command ?

(ie the code you return with the keyword
"return" in the main function of a program
written in C)



Sponsored Link
Ads by Google

Response Number 1
Name: JR
Date: June 19, 2000 at 09:30:21 Pacific
Reply:

Well, first, the return code isn't really the same as the value you return with the return command. It is, for some compilers, yes, but mostly, it's ignored. If you want to be sure to return a code, use some assembly code or something, like this:
MOV AL,(return code)
MOV AH,4Ch
INT 21h


How to retrieve the error code, anyway, is firstly different depending on what technique or command you use to execute the program (there are a lot of interrupts and C functions for this and they all have different advantages and drawbacks)
Supposing you start the program from a command prompt, or from a bat file, the return code is saved in a sort or pseudo-variable called ERRORLEVEL.
This does not show up the way that you could write something like ECHO %ERRORLEVEL to show the result, but can (as far as I know) only be used with IF statements, and only as the comparision 'equal or greater', and as there are no ELSE either, code will be very messy but work, like this:

IF ERRORLEVEL 4 ECHO Return code was greater than 3.
IF ERRORLEVEL 4 GOTO finish
IF ERRORLEVEL 3 ECHO Return code was 3.
IF ERRORLEVEL 3 GOTO finish
IF ERRORLEVEL 2 ECHO Return code was 2.
IF ERRORLEVEL 2 GOTO finish
IF ERRORLEVEL 1 ECHO Return code was 1.
:finish

Very unpractical, but it's not my fault. Rather Microsoft's idea of constructing a flexible batch file language.


0

Response Number 2
Name: W0rm
Date: June 19, 2000 at 16:06:49 Pacific
Reply:

good point. i want a IF ERRORLEVEL = 1! :) btw, if anyone knows any *really good* C programmers, I can get the source to BATLITE 1.73 (batch compiler)


0

Response Number 3
Name: nico
Date: June 21, 2000 at 01:43:35 Pacific
Reply:

thanks,
it seems that a
echo %ERRORLEVEL%
is working (at least with NT).


0

Response Number 4
Name: senthilraj
Date: January 4, 2001 at 22:51:38 Pacific
Reply:

I want error level when run a ftp script command how i can get that


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Who is this Hamlet guy? random computername in bo...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: error return by a prog

Can the registry be edited by a batch fi www.computing.net/answers/dos/can-the-registry-be-edited-by-a-batch-fi/5941.html

I want to know then space use by a direc www.computing.net/answers/dos/i-want-to-know-then-space-use-by-a-direc/6688.html

data error reading drive a www.computing.net/answers/dos/data-error-reading-drive-a/9982.html