Interactive programs ask you questions and respond appropriately to your answers (e.g. "if yes, do this, else do that"). The 'Batch File Language' consists of Dos commands that COMMAND.COM can interpret It is a primitive language, but strong enough to automate many straightforward sequences of commands, like those in your AUTOEXEC.BAT file. Batch files achieve limited flexibility because they can accept up to nine additional terms (parameters) entered on the command line after the batch filename (e.g. 'MYBATCH Tuesday B:' where Tuesday and B: would be two parameters). Once started, however, they can only respond to questions by pausing and offering to quit if you press Control+Break. To provide truly interactive batch files, therefore, requires help from .COM or .EXE programs not supplied with your DOS files and which are designed specially to ask questions and present batch files with answers that they can understand. You can then include these extra utilities in critical positions anywhere in batch files, with remarkably enhanced usefulness. These 'questioner' programs are of two kinds, as follows. 1. Single Key Press Detectors These wait until a key is pressed, and then do one of the following:
These wait until you've typed one or more words, and pressed Enter. They will then save what you've typed as an 'environment variable'. Such variables are distinguished by having their name enclosed in percent signs (for example, '%choice%'), and as such are available to all future programs in that session, or until they're erased (like 'set choice='). Many of these questioner programs are very cheap (they can be found in the Public Domain) and very valuable (because they make much better batch files). Some examples are:
The accompanying listing is an elegant example of a batch file which packs &/or unpacks compressed (archived) programs and data files on your hard disk, and after unpacking, offers to scan the decompressed files for viruses. It uses the above mentioned READKEY and READLN programs to ask numerous questions inside the batch file, and responds appropriately each time. Both utilities save keyboard responses as 'environment variables' with names you provide. These variables must be removed from RAM at the end of the program to prevent running out of environment space. If ever ARC.BAT halts with the message "Out of environment space", you must enlarge that space to, say, 512 bytes by inserting the following line in your CONFIG.SYS file (with a text editor), and then rebooting for the change to take effect: SHELL=C:\COMMAND.COM /P /E:512 Like all batch files, ARC.BAT has to be typed in a 'pure text-editor'. This means DOS's EDIT program, e or the decrepit Dos editor EDLIN, or in a word g processor (in which case you must save the file 'in ASCII format'). Before running ARC.BAT, make sure you also have the following files to be present in a directory (for 'example, C:\TOOLS) that is on your search path:
Reprinted from the November 1992 issue of PC Update, the magazine of Melbourne PC User Group, Australia |