@echo off
set filename=%date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%:%time:~6,2%
rem set "filename=%filename: =0%"
echo Current Time: %filename%
echo stop Tomcat...
rem 遍历结果集(多行),获取每行的第5个元素,保存最后一个数据
for /f "tokens=5" %%i in ('netstat -aon ^| findstr ":9091"') do (
set tomcat_pid=%%i
)
rem 如果pid存在,那么杀死进程
echo tomcat_pid=%tomcat_pid%
if '%tomcat_pid%' == '' (
echo tomcat没有启动,不需要杀死进程
) else (
echo Kill pid=%tomcat_pid%
taskkill /f /pid %tomcat_pid%
)
echo waiting...
rem TIMEOUT /t 10
echo WScript.sleep 5000 > sleep.vbs
Wscript sleep.vbs
del sleep.vbs
echo start Tomcat...
cd /d "D:\Joyone Server\Tomcat 8.5_JOYODC\bin"
call startup.bat
rem start "startTomcat" cmd /k call startup.bat
复制以上内容到记事本中并保存为bat文件
1、修改for /f "tokens=5" %%i in ('netstat -aon ^| findstr ":9091"') do (
中的9091为tomcat的访问端口
2、修改cd /d "D:\Joyone Server\Tomcat 8.5_JOYODC\bin"
中的路径为tomcat路径,使用定时
文章评论