General discussion

Locked

Setting the errorlevel?

By rejohnson ·
I need to reset the errorlevel in a DOS batch file to return a 0 (zero) on exit. Anybody know an easy way to do that?

Thanks,

Russell

This conversation is currently closed to new comments.

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

All Comments

Collapse -

Setting the errorlevel?

by jesalyer In reply to Setting the errorlevel?

ZDNet published a utility several years ago that does that. DCH1.01 and Enquire v2.7 are both available there and both should do what you want.

jeff s
spanish support analyst

Collapse -

Setting the errorlevel?

by rejohnson In reply to Setting the errorlevel?

Unfortunately, both utilities require keyboard input to set the errorlevel accordingly. I want to set it within the batch file (e.g., set errorlevel = 0)

Thanks anyway.

Collapse -

Setting the errorlevel?

by guy In reply to Setting the errorlevel?

Is this what you are looking for? Technet even includes DOS stuff! Technet ref Q57658

If you are writing a program that is going to be invoked from within an MS-DOS
batch file that uses the IF ERRORLEVEL command, you can use Interrupt 21H
Function 4CH, "Terminate Process with Return Code" to set the errorlevel in your
program. This function terminates the program and returns the errorlevel to the
parent process, which in this case is COMMAND.COM running the batch file.

The parametersfor Interrupt 21H, Function 4CH are AH = 4CH, AL = errorlevel,
followed by a call to Interrupt 21H. The errorlevel can be any value in the
range 0 to 255 (0 to FF, hexadecimal).

Collapse -

Setting the errorlevel?

by rejohnson In reply to Setting the errorlevel?

Sorry, I'm only running DOS commands...

Collapse -

Setting the errorlevel?

by tchieng In reply to Setting the errorlevel?

The easiest way to do it is simply write a utility program in Pascal and include that program in the batch file.

program Seterror;
begin
halt(0);
end.

You can even do it in C. Don't have a compiler? I can email it to you if you need it...

Back to Windows Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums