What is the Windows analog of the Linux watch command?
I'm looking for a Windows program/script/command line function that works like Linux's watch
program.
watch
periodically calls another program/whatever and shows the result, which is great for refreshing an output file or similar every second:
watch cat my-output.txt
or, more powerfully:
watch grep "fail" my-output.txt
I've looked for it in cygwin's library, but it doesn't seem to be present.
Solution 1:
watch
is available in Cygwin, in the procps
package as listed here (this info can be found via the package search on the website, here). I don't think this package is installed by the default cygwin setup, but it is one I usually select on new installs in order to have the watch command available.
The location of tools in packages usually match package names in Linux distributions (the package containing watch
is procps on Debian and Ubuntu too) so if the Cygwin package search function fails you, info for/from Linux distributions may offer clues.
Solution 2:
Write your own. Let's say file watch.bat
contains :
@ECHO OFF
:loop
cls
%*
timeout /t 5 > NUL
goto loop
and call it via, for example:
watch echo test
will echo test
every 5 seconds.
Solution 3:
Powershell has the while
command. You can use it like in Linux:
while (1) {your_command; sleep 5}
Linux version:
while true; do your_command; sleep5; done
Others:
while ($true) {netstat -an | findstr 23560; sleep 5; date}