Skip to content

Instantly share code, notes, and snippets.

@cypok
Last active August 29, 2015 14:21
Show Gist options
  • Save cypok/c9d1eff84ff59ccafa63 to your computer and use it in GitHub Desktop.
Save cypok/c9d1eff84ff59ccafa63 to your computer and use it in GitHub Desktop.
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 INTERVAL=2
set CMD=%*
)
:run
cls
@echo ON
%CMD%
@echo OFF
if errorlevel 1 ( goto :EOF )
timeout /t %INTERVAL% >nul 2>&1
goto :run
:usage
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