Stealing pages from the server...

Equivalent WATCH Command in Windows


Introduction

In Linux, the watch command is extremely handy for running a command on a regular basis and displaying the results. This is particularly useful if you need to keep track of any changes in the output of a command that is run repeatedly. The watch command has no direct equivalent in Windows, however the while loop in Windows PowerShell or the for loops in a Windows command-line prompt (CMD) can achieve the same result.

Using WATCH

Create a file called watch.bat inside C:\Windows\System32\ folder.

@ECHO OFF
:loop
  cls
  %*
  timeout /t 5
goto loop

For example, prefixing the docker ps command with watch works like this:

watch docker ps

Or you can use a top-like utility for monitoring CUDA on a GPU by the following command:

watch nvidia-smi

References

  1. https://opensource.com/article/21/9/linux-watch-command
  2. https://gist.github.com/gythialy/2800bcbec09df4664b3c
  3. https://blog.miniasp.com/post/2011/08/30/Implement-watch-command-for-Windows

Author: Yang Wang
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Yang Wang !
 Previous
Install Docker on Windows without Hyper-V Install Docker on Windows without Hyper-V
Docker is an open-source tool that allows you to run numerous software and operating systems in a containerised environment. The background story is that I wish to run an Android app on Mumu, and this app requires the Hyper-V service to be closed. However, I still need to use Docker to deploy my machine learning project, which requires Hyper-V to be enabled. This puts me in a very difficult position. So in this article, I will try to install and run Docker without using Hyper-V service.
2022-03-23
Next 
Run Octave Script from Command Line Run Octave Script from Command Line
Octave is an open-source replacement for MATLAB, a software and programming environment for numerical arithmetic and data analysis. Sometimes it's more convenient to run Octave scripts from the command line.
2021-12-24
  TOC