how do i set errorlevel when leaving a batch file?

  • Thread starter Thread starter Anthony Ewell
  • Start date Start date
A

Anthony Ewell

Hi All,

The answer to this must be right under my nose,
but I am not finding it.

How do I set the "errorlevel" when leaving a batch
file? I want to exit with a "0" or a "1".

Many thanks,
--Tony
 
Detlev said:
This old DOS utility should work, although tested under Win2K only.
http://garbo.uwasa.fi/pc/batchutil.html --> errorlvl.zip
Hi Detlev,

Thank you thank you thank you!

Usage: errorlvl n [$]

Sets the return code or batch file "ErrorLevel" to "n",
where 0 <=n<= 255.

$ - Display software registration and licencing information.

Exactly what I needed.

Thank you for the awesome link too! That page is batch programming
heaven.

--Tony
 
Anthony Ewell said:
Thank you thank you thank you!

You're certainly welcome, Anthony.
Thank you for the awesome link too! That page is batch programming
heaven.

Well, I was using several nice batch tools from that site for many years
and therefore, I didn't link directly to that particular file. Anyway,
there are other solutions also, this way was just one of them.
 
exit [error-level]

ie,

exit 1

or

exit 0

default is to leave error-level unchanged.

=======

to find this in xp help, search Help and Support for "exit command"

shd come up in XP Pro, XP Home may not have it tho, as Home omits the
command line help files. If so, you can access them online here:

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx

Thank you for the excellent link!

The batch file is being called from another batch file.
And, this scheme must work under both w2k and eXPensive.

Problem: "exit x" under w2k exits the command shell.
So, the calling script never gets returned to. Geez,
this stuff never stops. The "errorlvl" third party
command seems to be the best route. That or I should
finally get off my butt and finally learn Perl. :-)

Many thanks,
--Tony
 
Are you totally stupid.

Exit
Exits the current batch script or the Cmd.exe program (that is, the command interpreter) and returns to the program that started Cmd.exe or to the Program Manager.

Syntax
exit [/b] [ExitCode]

Parameters
/b
Exits the current batch script.
ExitCode
Specifies a numeric number.
/?
Displays help at the command prompt.
Remarks
a.. If you use /b outside of a batch script, it will exit Cmd.exe.
b.. If you use /b, Cmd.exe sets the ERRORLEVEL to the specified ExitCode. If you exit Cmd.exe, Cmd.exe sets the process exit code with the specified ExitCode.
 
David said:
Are you totally stupid.

Exit
Exits the current batch script or the Cmd.exe program (that is, the comman
exit [/b] [ExitCode]

Parameters
/b
Exits the current batch script.
ExitCode
Specifies a numeric number.
/?
Displays help at the command prompt.
Remarks
a.. If you use /b outside of a batch script, it will exit Cmd.exe.
b.. If you use /b, Cmd.exe sets the ERRORLEVEL to the specified ExitCode.

Yes, and thank you for the help.
 
Back
Top