4

So I have created a text adventure batch game, but after testing it on my home computer, none of the sleep commands work. My home PC is running Win 8.1 and the Laptop used to creating the game is running Win7. I don't know if this is the reason why the 'Sleep' function don't work..

But could anyone tell me the difference between sleep and timeout ? And why isn't the sleep commands working anymore?

YoloJoe
  • 155
  • 2
  • 3
  • 10

1 Answers1

6

Sleep is a Windows Scripting Host command (like JScript or VBScript). It's not really a cmd-interpreted batch thing.

Timeout is like a pause that auto continues after a specified time or on keypress (unless the /nobreak switch is used).

There's also waitfor, which pauses for X seconds or until a signal is received from another computer or window.

timeout and waitfor are included with Windows 7 and newer. For compatibility with earlier versions of Windows, traditionally, ping is used to simulate a pause like this:

ping -n 6 0.0.0.0 >NUL

... will pause for 5 seconds. (-n 6 means ping 6 times. The first ping response is instant, so N+1 is needed to pause N seconds.)

Some people also use choice /t to pause. See the How to sleep for 5 seconds in Windows Command Prompt related page if you'd like. There may be a reference to a utility or resource kit there you've installed that makes Sleep work on your Win 7 laptop, which has not been installed on your 8.1 desktop.

Community
  • 1
  • 1
rojo
  • 22,626
  • 5
  • 47
  • 93
  • That works, but now I have a very annoying "wating for 3...2...1... seconds, press CTRL+C to quit" message showing each time I use the command. Any way to hide the "debug message"? – YoloJoe Jan 21 '15 at 06:21
  • Just redirect the output: `timeout /T 5 /nobreak>nul` – JosefZ Jan 21 '15 at 09:18
  • `Timeout` seems to be also available in some older Windows versions: https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/cc754891(v=ws.11) – Piovezan Feb 02 '21 at 14:59