Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

up vote 1 down vote accepted

Use this:

@echo off
echo done
ping 127.0.0.0 -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 at 23:06

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

ECHO waiting 5 seconds...
CHOICE /C:AB /D A /T 5 > NUL
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 at 23:05

Your Answer

 
discard

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.