Skip to content

Instantly share code, notes, and snippets.

@dipsywong98
Created January 6, 2018 05:06
Show Gist options
  • Save dipsywong98/8dbd12ab7d0de6699ddcaeedbcdc4786 to your computer and use it in GitHub Desktop.
Save dipsywong98/8dbd12ab7d0de6699ddcaeedbcdc4786 to your computer and use it in GitHub Desktop.
php execute program with timeout using batch file in windows server
::param 1 is executable, param 2 is timeout seconds
echo "running %1 with timeout %2"
start %1
set time=0
:check
tasklist /FI "IMAGENAME eq %1" 2>NUL | find /I /N "%1">NUL
::time limit exceed
if "%time%"=="%2" goto kill
::program is running
if "%ERRORLEVEL%"=="0" ( ping 127.0.0.1 -n 2 >nul & set /a time=%time%+1 & goto check) else ( goto end)
:kill
echo "terminate"
taskkill /im %1 /f
:end
echo "end"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment