Wednesday, March 28, 2007

Exiting Batch Files

Sometimes when using SMS you want to use a Batch file to see if a file is present and preform an action, or maybe delete a file. When using batch files you can get the current error level for validation or set the error level to your liking. For instance you have a batch file that checks to see if a file is present, if so run a program, else exit. Lets say for instance that the Batch always exits with a error 1 but it should exit with a 0 and continue on with the next program. To get around do this in the batch file
---
Exit /b [error level]
Exit /b 0 <- this will allow you to exit with a successful exit code
----

or try this

-----
set errorlevel=0 <- this will allow you to exit with a successful exit code

-----


This should only be done if you have tested and know the desired out come. Forcing a successful exit can lead to other problems. Make sure you cover any possible errors that might occur in the Batch file