cmd 关闭进程java
taskkill /F /IM java.exe
taskkill /f /im java.exe
如何用dat批处理文件关闭某端口对应程序-Windows自动化命令
如何用dat批处理文件关闭某端口对应程序?
网上找到的大部分都是手动操作,第一步先查出端口,第二步在根据上一步查到的端口手动去关闭进程。但我的需求不是这样的,我需要全自动处理。用于 dubbo 服务进程在 Windows 环境下的关闭。如果 Linux 环境,则不需那么辛苦了。
找了大半天,终于在百度知道上得到参考案例(或许是我使用的关键词不对),并成功试验,感谢相关贡献者。
答案一:
for /f "tokens=1-5 delims= " %%a in ('"netstat -ano|findstr "^:指定端口号""') do taskkill /pid %%e
答案二:
@echo off set port=1234 for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port%"') do taskkill /pid %%m
我自己试验成功的脚本如下:
@echo off set port=20812 for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port%"') do ( echo kill the process %%m who use the port %port% taskkill /pid %%m )
循环读取一批端口,并查询对应PID是否存在,若存在则关闭,脚本如下:
@echo off for /l %%n in (20801,1,20812) do ( @echo find the process which use port [%%n] for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%%n"') do ( tasklist /FI "PID eq %%m"|find /i "PID" && ( echo PID:%%m 运行中,kill the process [%%m] who use the port [%%n] taskkill /F /pid %%m ) || echo PID:%%m 未运行 ) )
以上脚本,参考资料如下:
http://blog.csdn.net/painss/article/details/4431580
http://3y.uu456.com/bp_1fudk0d4or4n7xz5ebbq_1.html