|
In addition to the normal DOS commands, batch files have their own subcommand structure. Following are the subcommands in the order we will discuss them:
ECHOYou have seen one facet of ECHO already: it can send a message to the screen. More importantly, it can help clear the clutter on the screen when a batch file executes. Normally, the batch file commands would show on the screen as if you were typing them. This can get distracting. If you want to suppress the command echoing type:
To restart echoing, type: ECHO ON When ECHO is off no part of the actual DOS commands in the batch file will show on the screen. To display a message put it after the ECHO command:
As you will see, the REMark command also displays messages; but NOT if ECHO is off! Use ECHO if you want the message to show no mater what. REMarkREMark can be used to send messages to the screen or simply to document some part of your batch file's operation. Use them extensively in long batch files. The computer operator (it won't always be you) wants to know what is happening and, over time, you might forget what a complicated set of commands really does. The format is:
REMarks can be up to 123 characters long, although you usually won't want to go over the screen width so you can control the display. An undocumented, variation of this command is the period. In DOS 2.x, if a line in a batch file starts with one or more periods (.) it is treated as a remark. It is dangerous to use this however since in DOS 3.x and later that same line would be treated as the path to a command! PAUSEThe last "simple" command is PAUSE. Its basic function is to stop the execution of the batch file until you press a key. This can allow you to perform a necessary task; like perhaps changing a disk or verifying that a particular disk configuration is in place in order to avoid errors as the remaining parts of the batch file are executed. In early DOS versions PAUSE would optionally display a message. It does not now. In order to display a message you have to couple PAUSE with the ECHO command. The format in use now would require:
The message will show, followed by the DOS message:
GOTOThe format for this command is:
where LABEL is a line in your batch file that starts with a colon (:) followed by up to an eight character name (actually, you can type any number of characters, but DOS only recognizes the first eight). Want to create an endless loop? GOTO gives you an easy way. Here is one example:
When executed, this file will continue to print the endless loop line and the GOTO command until you tap Control-Break. Use this subcommand to transfer control in your batch files. If you want to terminate any batch file before it is complete, issue the break command [Control-Break]. Interim ReviewYou have now seen the simple stuff...Let's see how much of it stuck. Following are a few true/false questions. Think of the answer then look below to see if you were right. Questions:
Answers:
That's enough. You should now understand the batch file subcommands you are likely to need most often. Let's move on to the rest of the subcommands that allow you to program within a batch file. |
Please use the contact
form for questions or comments about this web site.
Copyright © 2001
Computer Knowledge, All Rights Reserved
Pray the Rosary for peace.