Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running a batch file on a server to dump a MySQL database.

I'd like to have the cmd window stray open for, say, 20 seconds, and then close. That's so if I run it manually I can see that it finished the task .

I tried Sleep 20, but it doesn't look like it works. The file is like this:

echo CAMS MySQL database backup

"d:\program files\mysql\mysql server 5.1\bin\mysqldump" -u xxxxxxx -pxxxxxx --result-file="D:\MySQL_Data_Backups\cams\cams.%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2%.sql" cams

echo Done!
sleep 20

When I run this, it closes the window without showing the final echo ("Done!").

If I use pause instead of sleep, it does show the final echo, but I would like the window to close after a delay.

Any suggestions as to what I have done wrong pls?

share|improve this question
up vote 1 down vote accepted

Use this:

@echo off
echo done
ping -n 1 -w 20000 > nul

-n 1 attempt to connect once -w 20000 waits 20 sec

@echo off just to have prettier output

Another one is:

timeout 20

This you can stop even before it counts down to 0.

share|improve this answer
"timeout 20" was my choice, nice that I can still close the window during the countdown. Cheers. – maxhugen Jan 12 '14 at 23:06

For the sake of completeness, here's an old-school method using the classic DOS choice command.

ECHO waiting 5 seconds...
share|improve this answer
I ended up using "timeout 20" as suggested by excrucio, but your suggestion worked just fine too. Cheers. – maxhugen Jan 12 '14 at 23:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.