Deniz Zoeteman
Deniz Zoeteman

Reputation: 10111

CMD: Sleep and hit any key, at the same time?

i have this batch file, which makes constantly a loop. I want the user to be able to terminate it in the batch, not just clicking the X.

This is what i need (somehow):

@echo off
:proc
cls
rem All kind of stuff...
echo Hit any key to terminate...
sleep 1
@pause>nul

But, of course, sleep and pause can't work at the same time.

How is it possible?

Upvotes: 0

Views: 652

Answers (2)

anon
anon

Reputation:

Remove the pause and change the message to "Hit Ctrl + C to terminate". Presumably the script has a "goto :proc" that you are not showing?

Upvotes: 4

Bob Peterson
Bob Peterson

Reputation: 31

More recent editions of Windows has the TIMEOUT command that does just this.

http://technet.microsoft.com/en-us/library/cc754891%28v=ws.10%29.aspx

Upvotes: 3

Related Questions