赞
踩
@echo off
set port=9090
for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port%"') do (
echo kill the process %%m who use the port
taskkill /pid %%m -t -f
goto q
)
:q
windows如何使用bat脚本后台启动/停止和重启jar包服务
2022-11-10 08:23:53
前提:windows上安装jdk
1.启动jar脚本
@echo off
START "app" javaw -jar app-0.0.1-SNAPSHOT.jar
2.停止jar脚本(如:jar包端口9090)
@echo off
set port=9090
for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port%"') do (
echo kill the process %%m who use the port
taskkill /pid %%m -t -f
goto q
)
:q
3.重启jar脚本(就是上面两个合起来)
@echo off
set port=9090
for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port%"') do (
echo kill the process %%m who use the port
taskkill /pid %%m -t -f
goto start
)
:start
START "app" javaw -jar app-0.0.1-SNAPSHOT.jar
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。