FYI (Note: The origin of this information may be internal or external to Novell. Novell makes every effort within its means to verify this information. However, the information provided in this document is FOR YOUR INFORMATION ONLY. Novell makes no explicit or implied claims to the validity of this information.) TITLE: Testing the DOS Errorlevel DOCUMENT ID#: FYI.P.6071 DATE: 04Dec92 PRODUCT: NetWare Lite PRODUCT VERSION: All versions SUPERSEDES: NA SYMPTOM: NA ISSUE/PROBLEM Testing the DOS Errorlevel Programs have the ability to set a flag in the DOS environment called errorlevel. This is usually used by the program to pass information to DOS, such as returning a pass or fail status of the particular program. This flag can be tested at the DOS level in the following format: IF not ERRORLEVEL x command where "not" is optional, "x" is the number to be tested, and "command" is the command to be issued if this test passes. Note: The purpose of this document is not to explain all of the functionality of the DOS ERRORLEVEL flag, but to give general information on how to use it with NetWare Lite. For further information, please consult your DOS documentation. NetWare Lite version 1.1 has the undocumented feature of setting the errorlevel flag. The NET command line utilities will set it according to the status of the command. Errorlevel is set to non-zero if the command "fails", or doesn't complete properly. For example, if the command NET LOGIN TOMMYJO was issued and the user TOMMYJO failed to login for whatever reason (entered an invalid password, no servers were found, etc.), the DOS errorlevel would be set to non-zero. If TOMMYJO was logged in properly, the errorlevel would be set to zero. The batch file on the next page demonstrates use of this command. The batch file will attempt to login user MURCHMAN to the network. If MURCHMAN is successfully logged in, the batch file will test to see if the server MAHONEY is on the network. If it is, the LPT1 port will be captured to the network printer LASER on server MAHONEY. Upon failing any of the above conditions, error messages will be displayed to the user. Only after everything has been completed will the application "PROGRAM" be executed. :LOGIN NET LOGIN MURCHMAN IF ERRORLEVEL 1 GOTO LOGINERR :CAPTURE NET SLIST MAHONEY IF ERRORLEVEL 1 GOTO SLISTERR NET CAPTURE LPT1 LASER MAHONEY ECHO You are logged in to NetWare Lite and port LPT1 has been ECHO captured to printer LASER. PAUSE GOTO DONE :LOGINERR ECHO. ECHO You were not correctly logged into the NetWare Lite. This ECHO program will not continue until you are correctly logged in. GOTO LOGIN :SLISTERR ECHO Server MAHONEY is not currently on the network. PAUSE :DONE CLS PROGRAM Note: The errorlevel flag is always tested at 1. Because of the way DOS evaluates the errorlevel, all non-zero values will pass on a test of 1.