How can I display my data from x.bat for 5 seconds?
When this code runs, it's impossible for me to see anything, it opens and closes immediately.
@ECHO OFF
:BEGIN
ECHO Authorized user
:END
If I use pause, the user still needs to hit a key to close the screen, that's why this should hap开发者_StackOverflowpen automatically.
@ECHO OFF
:BEGIN
ECHO Authorized user
pause
:END
Thanks
@ECHO OFF
:BEGIN
ECHO Authorized user
timeout 5 >nul
cls
:END
You can grab "sleep.exe" from the Windows Server 2003 resource kit and use sleep [seconds]
but the easiest way to get a set delay is to simply ping localhost N+1 times, where N is the number of seconds.
This will sleep for five seconds (there's no delay before the first ping, and a 1s delay after each):
ping -n 6 localhost>nul
SLEEP 5
GOTO:EOF
Would wait for 5 seconds before closing the window.
On Windows Vista and later you can use timeout
:
timeout 5 >nul
On ancient Windows versions you need to resort to ping
:
ping -n 6 localhost >nul 2>&1
An alternative way to use ping
, which also seems to be slightly less precise:
ping -n 1 -w 5000 1.0.0.0 >null
That is, convert seconds to milliseconds and use that as an argument of -w
parameter. The -n
parameter should have the argument of 1
. The host should be a knowingly inaccessible IP address.
variety of ways to resolve this
timeout /t 5 /nobreak >Nul
::for 5 sec
@PING 1.1.1.1 -n 2 -w 3000>nul
:: -n 2 for around 5-6 seconds
sleep 5 (EMERGENCY CASE)
精彩评论