2

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 happen automatically.

@ECHO OFF
:BEGIN
ECHO Authorized user
pause
:END

Thanks

Tom
  • 21
  • 1
  • 1
  • 2

6 Answers6

3
@ECHO OFF
:BEGIN
ECHO Authorized user
timeout 5 >nul
cls
:END
techraf
  • 59,327
  • 25
  • 171
  • 185
1

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
lunixbochs
  • 20,457
  • 2
  • 36
  • 45
1
SLEEP 5
GOTO:EOF

Would wait for 5 seconds before closing the window.

Shamit Verma
  • 3,845
  • 22
  • 22
1

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
Joey
  • 330,812
  • 81
  • 665
  • 668
0

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)
Kingzel
  • 368
  • 2
  • 9
0

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.

Andriy M
  • 73,804
  • 16
  • 91
  • 150