Skip to content

Instantly share code, notes, and snippets.

Last active Aug 29, 2015
What would you like to do?
Analog of watch (GNU command-line tool) for Windows
@echo OFF
REM watch is a GNU command-line tool that runs the specified command repeatedly
REM and displays the output on stdout so you can watch it change over time.
REM By default, the command is run every two seconds, although this is adjustable with the -n secs argument.
if x%1==x (call :usage %0 %* && exit /b 1)
if x%1==x-n (
if x%2==x (call :usage %0 %* && exit /b 1)
for /f "tokens=2*" %%a in ("%*") do (
rem ignore %%a==-n
set INTERVAL=%%a
set CMD=%%b
) else (
set CMD=%*
@echo ON
@echo OFF
if errorlevel 1 ( goto :EOF )
timeout /t %INTERVAL% >nul 2>&1
goto :run
echo Usage: %1 [-n ^<seconds^>] ^<command with args^>
goto :EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment