Recently, I published a blog post that detailed how to create a batch file to backup your files. Another thing I have needed to use in batch files is a wait command or something to make the batch file temporarily stop. In the post, I want to take a look at four good ways to essentially make your batch file wait.
Batch Timeout Command
The first way that I have seen this done is to use the timeout command. If you have a really old version of Windows, like XP or older, this might not work. However, this generally will do what you need. To make the your batch file wait for 5 seconds, you could use:
This will cause your batch file to wait for 10 seconds.
Batch Waitfor command
The next command you can use is the batch waitfor command. I think it is a much better idea to use the timeout command. However, if the timeout is not working for some reason, you can try the waitfor command. Here is an example:
waitfor nothing /t 10
This will cause your batch file to wait 10 seconds for the process “nothing” to finish. I don’t like this as much since there is no “nothing” process, so this command will error.
Batch Ping Command
Another round about way to perform a batch wait command is to use the ping command to an address that doesn’t exist with a specified timeout length. Yet again, I prefer the timeout command since this is a workaround solution. Here is an example though:
ping 22.214.171.124 -n 1 -w 10000 > nul
This will ping the address 126.96.36.199 and will timeout after 10000 milliseconds, or 10 seconds.
Batch Sleep Command
Another good way to perform a batch wait is to use the batch sleep command. If your computer has this command available, it is another great command to use. Many versions of Windows Server will have this installed by default. Here is an example:
This will cause the batch file to sleep for 10 seconds.
Hopefully, at this point, one of the solutions above has solved your problem.