后台运行jar以及通过端口杀死进程bat

喜欢而已 提交于 2021-01-08 20:42:06

一、后台运行jar

编辑start.bat:

@echo off
start javaw -Dfile.encoding=utf-8 -jar xxx.jar
echo start success
pause

二、通过端口杀死进程

编辑stop.bat:

@echo off & setlocal EnableDelayedExpansion

title kill port

for %%a in (8080) do (
  set pid=0
  for /f "tokens=2,5" %%b in ('netstat -ano ^| findstr ":%%a"') do (
	set temp=%%b
	for /f "usebackq delims=: tokens=1,2" %%i in (`set temp`) do (
	  if %%j==%%a (
		taskkill /f /pid %%c
		set pid=%%c
		echo The port associated process has been killed
	  ) else (
		echo Not native occupant port
	  )
	)
  )
  if !pid!==0 (
	echo The port is not occupied
  )
)

echo complete

pause

三、参考

https://blog.csdn.net/u014265785/article/details/105953295/

https://www.jb51.net/article/172169.htm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!