Pausing a batch file for amount of time [duplicate

2019-01-15 13:14发布

Possible Duplicates:
Sleeping in a DOS batch file
How to wait in a batch script

I have a program that is kicked off with a batch file.

The first module takes 10 seconds or so to initialize, and I want a way to "sleep" for 15 seconds before the second module is called, but I don't want it to require the user to hit a key like "pause" seems to require.

So, this is what I mean:

echo %PATH%

pause 10

echo %PATH%

In this example, I want there to be 10 seconds in between the echos. Is this possible? I've seen some examples using "ping 1.1.1.1" but it doesn't seem to work all the time correctly.

2条回答
闹够了就滚
2楼-- · 2019-01-15 13:36
ping -n 11 -w 1000 127.0.0.1 > nul

Update

Beginner's mistake. Ping doesn't wait 1000 ms before or after an request, but inbetween requests. So to wait 10 seconds, you'll have to do 11 pings to have 10 'gaps' of a second inbetween.

查看更多
倾城 Initia
3楼-- · 2019-01-15 14:00

If choice is available, use this:

choice /C X /T 10 /D X > nul

where /T 10 is the number of seconds to delay. Note the syntax can vary depending on your Windows version, so use CHOICE /? to be sure.

查看更多
登录 后发表回答