One of the things I like about Linux/Unix is that there are far more (and better) command-line tools available than the ones you get by default with Windows. One of the commonly used tools is 'watch' which simply repeatedly runs another command until you quit. This is useful for things like displaying the current contents of a log file, or maybe doing a directory listing so you can watch it to see when something has changed. As far as I know there is nothing similar in Windows so I wrote my own batch file which does the same thing:
@echo off
title Watching %1 %2 %3 %4 %5
:top
cls
%1 %2 %3 %4 %5
echo.
choice /C QC /M "Press Q to quit or C to continue" /t 3 /d c
if errorlevel==2 goto top
if errorlevel==1 goto end
:end
If you want to use it, copy the script above into a file called 'watch.cmd' and place that file somewhere in your path, e.g. C:\Windows\System32.
What happens in the script above is basically that the 1st parameter you supply would be the command to run and the following 4 parameters would be any switches or values you want to provide. Up to 4 extra switches can be provided although you can obviously change this to be as many as you like. The
choice command provides a 3-second delay and gives you the chance to quit watching by pressing
q or continue immediately by pressing
c — rather than waiting for the 3 seconds to elapse. Again, you can change the timeout from 3 seconds by changing the
/t 3 value to something else.
Now, say you want to monitor the output of a file named 'C:\error.log'. Use the command by entering
watch type c:\error.log and the file will be repeatedly typed on the console screen at 3 second intervals until you press q.
Easy!