views
- The timeout command lets you pause for specific number of seconds, until a user presses a key, or indefinitely.
- Use the pause command to delay the batch file until a user presses any key, or the choice command to give the user options to choose from.
- You can hide on-screen messages that indicate delay to the user by adding >nul to the end of the timeout, ping, and choice commands.
Timeout
Use the timeout command to specify the delay time in seconds. By inserting the timeout command into your batch file, you can prompt the batch file to wait a specified number of seconds (or for a key press) before proceeding. This command is available on all modern versions of windows, including Windows 10.
timeout /t
Pause
Use the pause command to suspend the batch file until a user presses a key. This simple command doesn't require any flags and you can place it anywhere in your script to prevent further action. When the pause command runs in the batch file, the user will see Press any key to continue . . . on a new line. When the user presses a key, the script continues. You might use pause right before a section of the batch file that you might not want to process, or before providing instructions to the user to insert a disk before continuing. At the pause, you can stop the batch program completely by pressing Ctrl + C and then Y.
Ping
Use ping to delay the next command in the script until a ping is complete. You can add a ping anywhere in your batch file, enter any hostname or IP address (including a nonexistent address), and specify the time in milliseconds to delay the next command. You'll also be able to hide the output of the ping so the user won't see what's happening in the background.
ping /n 1 /w
Choice
Use the choice command to delay until a user selects an option from a list. You can customize the list of choices, use the default options of Y or N, or choose not to display any choices at all and simply delay your script for a specific period of time.
choice [/c [
Sleep
If you're using Windows XP or earlier, you can use sleep to specify a wait time in seconds. This command will not work in any newer versions of Windows starting with Windows Vista, but is the easiest way to add wait time to batch files running on older systems.
sleep
Comments
0 comment