How can I execute (from a DOS batch script) a command every n (e.g. 5) seconds?
The command output should be shown at the command prompt "as usual".
This loop should be stoppable only by hitting Ctrl+C (or by closing the cmd.exe window by clicking the "x")
Peter
Execute a command every n seconds?
Moderator: DosItHelp
Re: Execute a command every n seconds?
Code: Select all
:LOOP
<execute command here>
PING -n 5 127.0.0.1>nul
GOTO LOOP
Re: Execute a command every n seconds?
SIMMS7400 wrote:Code: Select all
:LOOP
<execute command here>
PING -n 5 127.0.0.1>nul
GOTO LOOP
Why use "ping" instead of "timeout"? timeout is more precise and easier to remember.
Code: Select all
:loop
<command>
timeout /nobreak /t <time in seconds> > NUL
goto loop
Add "> NUL" at the end to hide the timeout output.
Re: Execute a command every n seconds?
Certain utilities don't like TIMEOUT, such as PsExec.
Re: Execute a command every n seconds?
SIMMS7400 wrote:Certain utilities don't like TIMEOUT, such as PsExec.
Would love to see an example.
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Execute a command every n seconds?
I could have sworn there was some version of Windows that didn't come with timeout...
Re: Execute a command every n seconds?
Yes, Windows XP has no "timeout.exe".
But for this task you could use "sleep.exe" which is contained in the Windows Server 2003 Resource Kit Tools:
If you don't need any other tool, then you could open "rktools.exe" using for example "7zip", then
"Open Inside" the (packed) file "rktools.msi", mark "sleep.exe" and extract just that file only.
penpen
But for this task you could use "sleep.exe" which is contained in the Windows Server 2003 Resource Kit Tools:
If you don't need any other tool, then you could open "rktools.exe" using for example "7zip", then
"Open Inside" the (packed) file "rktools.msi", mark "sleep.exe" and extract just that file only.
penpen