Monday, April 22, 2019

command line - Make Batch File Cmd Window Stay Open For X Seconds


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?


Answer



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.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...