windows 系统,优雅的杀死指定端口进程
chcp 65001
@echo off
set /p port=请输入端口号:
netstat -ano | findstr %port% > temp.txt
REM 提取进程号
for /f "tokens=5" %%a in (temp.txt) do (
set "pid=%%a"
goto :break
)
:break
del temp.txt
if "%pid%"=="" (
echo 找不到指定端口的进程。 > result.txt
) else (
taskkill /f /pid %pid%
echo 成功终止进程:%pid% > result.txt
)
创建文本文档,改成bar,双击运行即可,以后电脑卡了,idea报端口重复记不住命令就不用跑百度或者重启电脑了。