Created
January 6, 2018 05:06
-
-
Save dipsywong98/8dbd12ab7d0de6699ddcaeedbcdc4786 to your computer and use it in GitHub Desktop.
php execute program with timeout using batch file in windows server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
::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