TITLE: Sample Configuration and Batch Processing Fil DOCUMENT ID: TID14918 DOCUMENT REVISION: 1 DATE: 27FEB94 ALERT STATUS: Yellow README FOR: NA NOVELL PRODUCT and VERSION: Novell DOS 7 ABSTRACT: NA --------------------------------------------------------------------- DISCLAIMER: 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. --------------------------------------------------------------------- ISSUE: NOVELL DOS 7 has greatly enhanced CONFIG and BATCH commands. This document provides examples of how these various commands can be used. For more information on batch file commands and syntax refer to DOSBOOK, the NOVELL DOS 7 online User Guide. Also reading the following chapters from DOSBOOK would be particularly helpful: Chapter 7, "Batch Processing" Chapter 8, "Command Reference" Chapter 9, "Configuring the System" Batch commands that were added since DR DOS 6.0 are the following: ? Allows a yes or no branch in the same manner as the "?" in the DR DOS 6.0 CONFIG.SYS command. DIREXIST Added to evaluate whether a directory exists. CHOICE Returns an error level for evaluation. Only the basic ideas are outlined in each example that follows. A batch file that illustrates the new NOVELL DOS 7 commands and their use is at the end of this document. EXAMPLE 1 - THE USE OF GOTO IN THE CONFIG.SYS FILE ?"Do you want to run QEMM (y/n)? " goto QEMM ?"Do you want to run MemoryMAX (y/n)? " goto NWDOS :QEMM DEVICE=C:\QTR_DECK\QEMM386.SYS DEVICE=C:\NWDOS\HIMEM.SYS (additional QEMM driver lines go here...) goto COMMON :NWDOS DOS=UMB DEVICE=C:\NWDOS\EMM386.EXE /F=AUTO... ... :COMMON files=40 buffers=20 The GOTO statement is used to proceed directly to a label. This function works similar to the GOTO statement found in batch file processing. EXAMPLE 2 - THE USE OF CHAIN IN THE CONFIG.SYS FILE This example shows that you can link to other files that hold your configurations for each system setup. In the following CONFIG.SYS file, the two lines direct the configuration process to the QCONFIG and MCONFIG.SYS files. The appropriate FILES, BUFFERS, and so forth, information is contained within those files and not within the main CONFIG.SYS file. If the response to both questions is no, a default configuration begins. The RETURN command cannot be used to return to the parent CONFIG.SYS file. ?"Do you want to run QEMM (y/n)? " chain=QCONFIG.SYS ?"Do you want to run MemoryMAX (y/n)? " chain=MCONFIG.SYS files=40 buffers=20 EXAMPLE 3 - USING "?" IN BATCH FILES When you run a batch file containing a "?" statement, a response to the prompt is required by the user before processing continues. Please note that the maximum length of a batch file statement (including the ?) is 128 characters. The following statement in a batch file causes the system to prompt the user before deleting all the files with the extension .OLD from C:\ACCOUNTS: ?DEL C:\ACCOUNTS\*.OLD So, when the file executes, the user sees the following prompt: DEL C:\ACCOUNTS\*.OLD (Y/N) ? If the user answers Y, the DEL command is run and the files are deleted. If the user answers N, the command is ignored and the next line in the batch file is processed. EXAMPLE 4 - USING SWITCH/RETURN AND LABELS Processing pauses on the SWITCH command until an option is chosen. The appropriate option is selected by choosing a number. The SWITCH command then goes to the corresponding label. In the following example, 1 selects the label :XMS, 2 selects the label :EMS, and so forth. The RETURN command will return processing to the line after SWITCH. Notice the use of the ECHO statement for setting up the menu options. ECHO = Choose which Memory you want and how to use it ECHO = ECHO = 1 (or ENTER) XMS Memory ECHO = 2 EMS Memory ECHO = 3 DPMI ON, XMS ECHO = 4 DPMI ON, EMS ECHO = ECHO = Make your selection... SWITCH XMS, EMS, DPMI_ON1, DPMI_ON2 GOTO DEFAULTS :XMS DEVICE=C:\NWDOS\EMM386.EXE /F=NONE /R=AUTO RETURN :EMS DEVICE=C:\NWDOS\EMM386.EXE /F=AUTO /R=AUTO RETURN :DPMI_ON1 DEVICE=C:\NWDOS\EMM386.EXE /F=NONE /R=AUTO /DPMI=ON RETURN :DPMI_ON2 DEVICE=C:\NWDOS\EMM386.EXE /F=AUTO /R=AUTO /DPMI=ON RETURN :DEFAULTS SHELL=C:\COMMAND.COM \C: /P /E:512 BUFFERS=20 FILES=30 DEVICEHIGH=C:\NWDOS\DPMS.EXE etc... EXAMPLE 5 - HOW TO USE ENVIRONMENT VARIABLES IN THE CONFIG.SYS The use of variables in the CONFIG.SYS file is not quite the same as in batch files. Because the command processor (COMMAND.COM) is not loaded until after the command in the CONFIG.SYS file have been processed, the environment variables are only stored. These variables are then passed to the command processor, where they can be tested and processed through the AUTOEXEC.BAT file or other batch files. Testing an environment variable is not possible in the CONFIG.SYS file. The CLS, CPOS, EXIT and SET commands are featured in this example: :DEFAULTS SHELL=C:\COMMAND.COM \C: /P /E:512 BUFFERS=20 FILES=30 etc.... ECHO = Choose which TSRs and Utilities you want loaded at BOOT ECHO = time for this session. ECHO = ECHO = 1 (or ENTER) None... just continue ECHO = 2 Mouse & Cursor Drivers ECHO = 3 Keyboard "Speeder" ECHO = 4 Novell Network ECHO = 5 Done with selections ECHO = ECHO = Make your selection... :MORE CPOS 10,33 SWITCH NOTHING, CURSMOUS, SPEEDKEY, NOVELL, DONE GOTO MORE :NOTHING :DONE CLS EXIT :CURSMOUS SET THINGS=ON RETURN :SPEEDKEY SET SPEEDKEY=ON RETURN :NOVELL SET NETWORK=ON RETURN The AUTOEXEC.BAT file now allows testing of the environment variables and executes commands based upon the conditionals illustrated below: @ECHO OFF VERIFY OFF PATH C:\;C:\NWDOS;C:\BATS;C:\TOOLS;C:\WINDOWS if "%things%"=="on" prompt $e[s$e[0;70H$e[1;36m$t$e[u$e[1;36mDRDOS6$p$g$e[2;32m if not "%things%"=="on" PROMPT [NOVELL DOS 7] $P$G SET TEMP=C:\TEMP IF NOT "%TEMP%"=="" MD %TEMP% >NUL if "%things%"=="on" LH MOUSE if "%things%"=="on" LH CURSOR /s10 if "%speedkey%"=="on" c:\nwdos\mode con:rate=30 delay=1 if "%network%"=="on" LH c:\lan\ipx if "%network%"=="on" LH c:\lan\net3 EXAMPLE 6 - THE CHOICE COMMAND IN BATCH FILES The CHOICE command is an external program that returns an ERRORLEVEL for certain preselected keys. They can then be tested with IF to make branches in a batch file. Up to 99 different errors can be returned. Three lines were used to create this example: CHOICE /C:XY Select X or Y for a message ... CLS IF ERRORLEVEL 2 ECHO MESSAGE: CHOICE RETURNED AN ERRORLEVEL OF 2 IF ERRORLEVEL 1 ECHO MESSAGE: CHOICE RETURNED AN ERRORLEVEL OF 1 The switch /C:XY instructs choice to use the keys X and Y. They are not case sensitive. The letter X will be errorlevel 1 and Y will be errorlevel 2. The remaining text is the displayed message. Because you chose the letter Y you actually received two messages. This points out one of the tricks to using ERRORLEVEL. When the ERRORLEVEL is tested, a logic is used that considers the statement to be true if the value is equal to or greater than the returned error. In the example used here: ERRORLEVEL=2 (letter Y), is true so the message is displayed. The second statement IF ERRORLEVEL 1 is also true (because the returned value of 2 is greater than or equal to 1) so the message is displayed. You should always perform the IF tests beginning with the highest ERRORLEVEL first. This is because the IF evaluates the statement based on whether the returned value is equal or greater than the IF statement. In the example used here: ERRORLEVEL=1 (letter X). The first statement IF ERRORLEVEL 2 is FALSE, so the message is not displayed. The second statement IF ERRORLEVEL 1 is true so the message is displayed. This example used an ECHO; however, a GOTO works best on ERRORLEVEL. This prevents you from going to the next IF ERRORLEVEL (which is 0 and will also be true). The syntax for the GOTO is: IF ERRORLEVEL 2 GOTO label2 IF ERRORLEVEL 1 GOTO label1 :label2 ECHO = CHOICE RETURNED AN ERRORLEVEL OF 2 :label1 ECHO = CHOICE RETURNED AN ERRORLEVEL OF 1 EXAMPLE 7 - DIREXIST IN THE IF COMMAND This command when used with IF will check to see if a directory exists: IF DIREXIST F:\ GOTO [:label] The DIREXIST command can be used to test for the existence of drives such as DISK's as well as any subdirectory on a disk. All disk drive have a root directory, so testing for F:\ (as in this example) will test for the existence of the drive as well as the directory. Network drives can be tested. OTHER EXAMPLES 1. Selecting different configuration options from the CONFIG.SYS file using the ? command. ?SHELL=C:\COMMAND.COM C:\ /P /E:512 ?SHELL=C:\COMMAND.COM C:\ /P /E:1024 ?BREAK=OFF ?BREAK=ON BUFFERS=20 FILES=20 ?HISTORY=ON, 256, ON, OFF, OFF ?DEVICE=C:\NWDOS\ANSI.SYS 2. Selecting different AUTOEXEC.BAT's from CONFIG.SYS using the ? and the SHELL statement. In the SHELL statement the /P switch can be followed by a file name. When present, the named file will be executed instead of the AUTOEXEC.BAT file. The named file must have a .BAT extension and cannot exceed 11 characters including path. ?"Default Autoexec? (y/n) "SHELL=C:\COMMAND.COM C:\ /P /E:256 ?"Alternate Autoexec? (y/n) "SHELL=C:\COMMAND.COM C:\ /P:ALTERNAT.BAT /E:256 3. Selecting and using different configuration files from CONFIG.SYS at bootup. ?"Do you want to run Windows? (y/n) " chain = WCONFIG.SYS ?"Do you want to use QEMM? (y/n) " chain = QCONFIG.SYS ?"Do you want to use MemoryMAX? (y/n) " chain = MCONFIG.SYS ?"Do you want to use 386MAX? (y/n) " chain = 386CONF.SYS Each line is printed on the screen and you are asked to load and run the chained configuration file. Each configuration file is a complete CONFIG.SYS type file with all the appropriate options. 4. The above configuration using "menu" choices with SWITCH. Note how the "SET environment" variables can be used and tested for different AUTOEXEC type files in this example. CONFIG.SYS ECHO = 1 For Windows Configuration ECHO = 2 For QEMM Configuration ECHO = 3 For NOVELL DOS 7 MemoryMAX Configuration ECHO = 4 For 386MAX Configuration ECHO = 5 For no Configuration... just exit SWITCH win, qemm, memm, 386m, none :none set autoexec=norm exit :win set autoexec=win chain=wconfig.sys :qemm set autoexec=qemm chain=qconfig.sys :memm set autoexec=memm chain=mconfig.sys :386m set autoexec=386m chain=386conf.sys AUTOEXEC.BAT @echo off PATH C:\NWDOS;C:\;C:\UTIL; VERIFY OFF PROMPT $P$G DISKMAP C: D: IF "%autoexec%"=="norm" goto NWDOSEXIT SHARE /L:40 IF "%autoexec%"=="win" SUPERPCK /EM /L:2048 IF "%autoexec%"=="qemm" CALL QEMM.BAT IF "%autoexec%"=="memm" SUPERPCK /A /L:2048 IF "%autoexec%"=="386m" CALL 386.BAT :NWDOSEXIT 5. Using ANSI ANSI escape sequences can be used in batch file processing to create colorful menus. Below is an example of a menu that uses the SWITCH command and ANSI escape sequences to create a menu. ANSI.SYS must be loaded in the CONFIG.SYS file to allow for cursor positioning and colors. The first character after the Echo statement is an ASCII 27 or escape character. This character may be displayed differently on some printers and monitors (in fact if you have ANSI loaded you will never see the character when typed to the screen). To type this character using the NOVELL DOS 7 EDIT, press the +

then the ESC key. An alternate method is to press +Q then the N key and then type the number 27. Within EDIT, the ESC character will appear as: ^[. If you have downloaded this document from CompuServe or the Novell Desktop System Group BBS, the escape sequences have been left intact and you can use the NOVELL DOS 7 EDIT to block out the Echo statements to a file. Then, if ANSI is loaded when the file is typed to the screen, you should see white letters on a magenta background. For additional information on ANSI.SYS and escape sequences, refer to Chapter 9 of DOSBOOK, the NOVELL DOS 7 online User Guide. @ECHO OFF ECHO [0;1;37;45m---------------------------------[0m ECHO [1;37;45m 1. CONTINUE W/O SCAN [0m ECHO [1;37;45m 2. SCAN FOR VIRUSES [0m ECHO [1;37;45m [0m ECHO [40;1;37m-----------------------------------[0m SWITCH MENUBEGIN,SCAN SAMPLE.BAT If you have gotten this file from CompuServe or the NOVELL Desktop Systems Group BBS, you can run this sample batch file. Starting on the next line, mark a block to the end of file (excluding any word processor control characters) and write the block to a new file called SAMPLE.BAT. From the command prompt SAMPLE will run the file. CLS @ECHO OFF REM EXAMPLE1 ****************************************** ECHO This batch file demonstrates some of the unique ECHO features of Novell DOS batch commands. ECHO. ECHO. ECHO The first example tests to make sure you are using ECHO Novell DOS. It uses an IF statement. The IF ECHO tests for an environment variable called OS. ECHO Press a key to begin. PAUSE>NUL ECHO. ECHO The Operating System variable indicates "%OS%". IF NOT "%OS%"=="NWDOS" GOTO WRONGDOS ECHO This means that the current operating system ECHO is Novell DOS. ECHO. ECHO Below is the line that was used in the batch file: ECHO. ECHO IF NOT "%%OS%%"=="NWDOS" GOTO WRONGDOS ECHO. ECHO The environment table contains the line: OS=%OS%. ECHO This was inserted automatically by Novell DOS. ECHO The batch processor replaces "%%OS%%" with "%OS%" ECHO from the environment table. Since "%OS%" is ECHO equal to "NWDOS", the statement is false and the ECHO GOTO is not executed. ECHO. ECHO IF statements are only executed if TRUE. The ECHO logic of the above statement can be confusing ECHO because at first glance it looks true. However, ECHO the NOT portion reverses the statement to ECHO something like "IF "%OS%" IS NOT EQUAL TO ECHO "NWDOS" THEN GOTO WRONGDOS." Press any key when ECHO you are ready to continue. PAUSE>NUL CLS REM EXAMPLE2 ****************************************** ECHO. ECHO This next example is the CHOICE command. ECHO. CHOICE /C:XY Select X or Y for a message ... CLS IF ERRORLEVEL 2 ECHO MESSAGE: CHOICE RETURNED AN ERRORLEVEL OF 2 IF ERRORLEVEL 1 ECHO MESSAGE: CHOICE RETURNED AN ERRORLEVEL OF 1 ECHO. ECHO The CHOICE command is an external program that ECHO returns an ERRORLEVEL for certain preselected keys. ECHO They can then be tested with IF to make branches ECHO in a batch file. Up to 99 different errors can be ECHO returned. Three lines were used to create this ECHO example: ECHO. ECHO CHOICE /C:XY Select X or Y for a message ... ECHO IF ERRORLEVEL 2 ECHO MESSAGE: CHOICE RETURNED ECHO AN ERRORLEVEL 2 IF ERRORLEVEL 1 ECHO ECHO MESSAGE: CHOICE RETURNED AN ERRORLEVEL 1 ECHO. ECHO The switch /C:XY tells choice to use the ECHO keys X and Y. They are not case sensitive. ECHO The letter X will be errorlevel 1 and ECHO Y will be errorlevel 2. The remaining text ECHO is the displayed message. ECHO. IF ERRORLEVEL 2 ECHO Because you chose the letter Y you actually received two messages. IF ERRORLEVEL 2 ECHO This points out one of the tricks to using ERRORLEVEL. When the IF ERRORLEVEL 2 ECHO ERRORLEVEL is tested a logic is used that considers the statement to be IF ERRORLEVEL 2 ECHO true if the value is equal to or greater than the returned error. In the IF ERRORLEVEL 2 ECHO example used here: ERRORLEVEL=2 (letter Y), IF ERRORLEVEL 2 ECHO is true so the message is displayed. The second statement IF ERRORLEVEL 2 ECHO IF ERRORLEVEL 1 is also true (because the returned value of 2 is greater IF ERRORLEVEL 2 ECHO than or equal to 1) so the message is displayed. IF ERRORLEVEL 2 GOTO ERROR2 IF ERRORLEVEL 1 ECHO You should always perform the IF tests beginning with the highest IF ERRORLEVEL 1 ECHO ERRORLEVEL first. This is because the IF evaluates the statement based IF ERRORLEVEL 1 ECHO on whether the returned value is equal or greater than the IF statement. IF ERRORLEVEL 1 ECHO In the example used here: ERRORLEVEL=1 (letter X). The first statement IF ERRORLEVEL 1 ECHO IF ERRORLEVEL 2 is FALSE so the message is not displayed. The second IF ERRORLEVEL 1 ECHO statement IF ERRORLEVEL 1 is true so the message is displayed. This IF ERRORLEVEL 1 ECHO example used an ECHO but a GOTO works best on ERRORLEVEL. This prevents IF ERRORLEVEL 1 ECHO you from going to the next IF ERRORLEVEL (which is 0 and will also be IF ERRORLEVEL 1 ECHO true). EDIT this batch file to see how the tests are performed. :ERROR2 pause CLS REM EXAMPLE3 ****************************************** ECHO. ECHO Next is a check to see if a directory exists. Novell ECHO DOS has a command called DIREXIST. This command ECHO when used with IF will check to see if the ECHO directory F:\ exists. Press any key to begin. PAUSE>NUL IF DIREXIST F:\ GOTO EXIST CLS ECHO. ECHO The directory does not exist! ECHO The command was: ECHO. ECHO IF DIREXIST F:\ GOTO EXIST ECHO. ECHO The directory did not exist, so the GOTO was ECHO not executed. ECHO. ECHO The DIREXIST command can be used to test for the ECHO existence of drives such as VDISK's as well as any ECHO subdirectory on a disk. All disk drive have a root ECHO directory so testing for F:\ (as in this example) ECHO will test for the existence of the drive as well ECHO as the directory. Network drives can be tested. GOTO EXAMPLE4 :EXIST CLS ECHO. ECHO The directory exists! ECHO The command was: ECHO. ECHO IF DIREXIST F:\ GOTO EXIST ECHO. ECHO The directory does exist, so the GOTO was ECHO performed. ECHO. ECHO The DIREXIST command can be used to test for the ECHO existence of drives such as VDISK's as well as any ECHO subdirectory on a disk. All disk drives have a ECHO root directory so testing for F:\ (as in this ECHO example) will test for the existence of the drive ECHO as well as the directory. Network drives can ECHO be tested and in fact F:\ may be one of your ECHO network drives. ECHO. REM EXAMPLE4 ****************************************** :EXAMPLE4 ECHO Press any key to continue PAUSE>NUL CLS ECHO The SWITCH command can be used in both Batch ECHO files and Config files. It waits for a number ECHO to be entered and then performs a GOSUB. The ECHO TIMEOUT command used in the CONFIG.SYS file ECHO will result in the first option being chosen. ECHO Also, the ENTER key will also be accepted as ECHO the first option. ECHO. ECHO Select 1 or 2 ECHO. ECHO Option 1 has a RETURN. Option 2 does not have ECHO a RETURN and functions like a GOTO. ECHO. SWITCH LABEL1,LABEL2 ECHO. ECHO This is the RETURN. GOTO PRELUDE1 :LABEL1 CLS ECHO This is the first switch! RETURN :LABEL2 CLS ECHO This is the second switch! ECHO. ECHO The SWITCH lines looked like this: ECHO SWITCH LABEL1,LABEL2 ECHO ECHO. ECHO ECHO This is the RETURN. ECHO GOTO PRELUDE1 ECHO. ECHO :LABEL1 ECHO ECHO This is the first switch! ECHO RETURN ECHO. ECHO :LABEL2 ECHO ECHO This is the second switch! ECHO etc... ECHO. ECHO :PRELUDE1 ECHO. ECHO You selected the key 2 so SWITCH did a GOSUB ECHO to the label :LABEL2. There was no RETURN in ECHO LABEL2 so it continued to the LABEL, PRELUDE1. ECHO Press any key to continue. PAUSE>NUL GOTO EXAMPLE5 :PRELUDE1 ECHO. ECHO The SWITCH lines looked like this: ECHO SWITCH LABEL1,LABEL2 ECHO ECHO. ECHO ECHO This is the RETURN. ECHO GOTO PRELUDE1 ECHO. ECHO :LABEL1 ECHO ECHO This is the first switch! ECHO RETURN ECHO. ECHO :LABEL2 ECHO ECHO This is the second switch! ECHO etc... ECHO. ECHO :PRELUDE1 ECHO. ECHO You selected the key 1 so SWITCH did a GOSUB to ECHO the label :LABEL1. The RETURN brought it back ECHO to the line immediately after the SWITCH. ECHO Press any key to continue. PAUSE>NUL REM EXAMPLE5 ****************************************** :EXAMPLE5 CLS ECHO This example displays some of the System ECHO Information Variables (SIV's). The SIV's are ECHO special variables that can be used in batch ECHO files to help control execution or just to make ECHO the OS "friendlier". Press any key to continue. PAUSE>NUL ECHO. ECHO Good %Greeting_Time%. The current computer time ECHO is %Hour24%:%Minute%:%Second%. ECHO. ECHO Today's date is %Month_Name% %Day%, %Year%. ECHO. IF NOT "%Login_Name%"=="" ECHO You are logged into the Network as %Login_Name%. ECHO. IF NOT "%Station%"=="" ECHO You are attached to station %Station%. ECHO. GOTO END :WRONGDOS ECHO. ECHO If you were running Novell DOS the OS variable ECHO would return "NWDOS." Since all of the tests ECHO performed by this batch file need Novell DOS ECHO to work correctly this batch program will now ECHO stop. Please try again when Novell DOS is running. ECHO. :END ECHO Thanks for running this Sample batch file. ECHO Please feel free to explore the contents of the ECHO file. The examples displayed in this file are ECHO fairly straightforward. Much more sophisticated ECHO batch files can be easily made. Experiment! --------------------------------------------------------------------- Any trademarks referenced in this document are the property of their respective owners. Consult your product manuals for complete trademark information. ---------------------------------------------------------------------