TITLE: PNW: Testing the DOS ErrorLevel DOCUMENT ID: TID1200867 DOCUMENT REVISION: 0 DATE: 19JUN95 ALERT STATUS: Yellow README FOR: NA NOVELL PRODUCT and VERSION: PERSONAL NETWARE V1.0 ABSTRACT: NA --------------------------------------------------------------------- DISCLAIMER: THE ORIGIN OF THIS INFORMATION MAY BE INTERNAL OR EXTERNAL TO NOVELL. NOVELL MAKES EVERY EFFORT WITHIN ITS MEAN 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. --------------------------------------------------------------------- ISSUE: PNW: TESTING THE DOS ERRORLEVEL Programs can 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 * The "not" is optional. * The "x" is the number to be tested. * The "command" is the command to be issued if this test passes. NOTE: The purpose of this document is to give general information on how to use it with Personal NetWare and not to explain all the functionality of the DOS ERRORLEVEL flag. For further information, please consult your DOS documentation. Personal NetWare v1.0 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 does not complete properly. Example: If the command NET LOGIN USER1 was issued and the user USER1 failed to log in for whatever reason (entered an invalid password, no servers were found), the DOS errorlevel would be set to non-zero. If USER1 was logged in properly, the errorlevel would be set to zero. The following batch file demonstrates use of this command. The batch file will attempt to log in user USER1 to the network. If USER1 is successfully logged in, the batch file will test to see if the server SERVER1 is on the network. If it is, the LPT1 port will be captured to the network printer LASER on server SERVER1. Upon failing any of the above conditions, error messages will be displayed to the user. Only after everything has been completed will the PROGRAM application be executed. :LOGIN NET LOGIN USER1 IF ERRORLEVEL 1 GOTO LOGINERR :CAPTURE NET SLIST SERVER1 IF ERRORLEVEL 1 GOTO SLISTERR NET CAPTURE LPT1 LASER SERVER1 ECHO You are logged in to Personal NetWare and ECHO port LPT1 has been captured to printer LASER. PAUSE GOTO DONE :LOGINERR ECHO. ECHO You were not correctly logged into the Personal NetWare. ECHO This program will not continue until you are correctly ECHO logged in. GOTO LOGIN :SLISTERR ECHO Server SERVER1 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. --------------------------------------------------------------------- Any trademarks referenced in this document are the property of their respective owners. Consult your product manuals for complete trademark information. ---------------------------------------------------------------------