The watch
command in Linux is used to execute a command periodically and show the output.
This is extremely useful if you need to track any changes in the output of a repeatedly executed command.
There is no direct equivalent for the watch
command in Windows, however the same result can be achieved using the while
loop in a Windows PowerShell or the for
loops in a Windows command-line prompt (CMD).
Cool Tip: Windows lsusb
command equivalent in PowerShell! Read more →
`Watch` Command in Windows
Use the oneliners below to execute some command periodically (each 5 seconds) and print the output of each execution.
The watch
command equivalent in Windows command-line prompt (CMD):
C:\> for /l %g in () do @(<command> & timeout /t 5)
The watch
command equivalent in Windows PoweShell:
PS C:\> while (1) {<command>; sleep 5}
Thanks for this.
To emulate watch displaying on a clear screen instead of scrolling I prepended the DOS “cls”
C:\> for /l %g in () do @(cls & & timeout /t 5)
This will repeat the command indefinitely. `watch` provides the ability to do something different when the output changes. With this simple loop, I have to add my own output comparison routine, making this not the same as `watch`
Thank U
This worked for me:
while (1) {cls;nvidia-smi;sleep 1}