| |
Usually, DOS executes a batch file without stopping. DOS stops processing the batch file while the program runs when the batch file loads a program. As soon as you exit the program, or an automatic termination occurs, DOS immediately continues processing the batch file from where it left off. Typically this is what you want, but sometimes you want to give the user time to think, react, and then take action. An example would be giving the user a group of choices that you want them to select from before proceeding.
PAUSE is the command we are looking for. PAUSE stops the batch file until almost any key is pressed. A key that would produce a character on the screen needs to be pressed. Therefore pressing a key like Ctrl or Alt or Shift will not exit out of the pause status. We used this command above to see the output. Now we will use this to pause the execution of the batch script.
Though the PAUSE command is really quite helpful, it lacks in power. The keystroke that you press is not capable of being used as a menu selection nor can it be saved in the program in any other way. Below is an example to illustrate how the PAUSE command works along with the ways of terminating a program with the keyboard.
1: 2: 3: 4: 5: 6: 7: 8: 9: |
|
|
|
|
|
|
|
|
| :: PAUSEIT.bat :: Example of the PAUSE command :: and the ways to exit out of a program @ECHO OFF ECHO The next command is a PAUSE ECHO Do NOT press Ctrl+C or Ctrl+Break PAUSE ECHO Press Ctrl+C or Ctrl+Break PAUSE  |
|
|
|
|
|
|
|
|
|
The first line is a comment with the name of the file. The second and third line comment is a description of the program (batch file). The fourth line turns command-echoing off. Line 5 and 6 gives the first message about which keys you can press for the first example. Line 7 is the PAUSE command that stops the batch file until a key is pressed. The next line (8) displays the message about aborting the program using the keyboard controls. The last line (9) is the final PAUSE that finishes the program.
| |
|
| |
|