How to set errorlevel env variable properly from a simple batch file: Answered

R

rajenk

Hello,

Here is a sample batch file that will set the errorlevel environment
variable correctly from with in a batch file

@echo off
set ERRORCODE=234
exit /B %ERRORCODE%

Happy Scripting!!

Thanks
Raj
 
A

Andrew McLaren

Here is a sample batch file that will set the errorlevel environment
variable correctly from with in a batch file

@echo off
set ERRORCODE=234
exit /B %ERRORCODE%

Actually there's no need to define a separate %ERRORCODE% variable, you can
use a literal. The following would also work:

@echo off
exit /B 234

You might decide to have a %ERRORCODE% variable for reasons of programming
style; but it's not functionally required, just to set the %ERRORLEVEL%.
(Also it might be easy to confuse the user-defined %ERRORCODE% and
system-supplied %ERRORLEVEL% identifiers).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top