@echo off setlocal enabledelayedexpansion echo =================================== echo Kill Process on Port 8000 echo ===================================echo. REM Find PID using port 8000 for /f "tokens=5" %%a in ('netstat -ano ^| findstr ":8000" ^| findstr "LISTENING"') do ( set "PID=%%a" ) if "%PID%"=="" ( echo No process found on port 8000 ) else ( echo Found process PID: %PID% on port 8000 taskkill /F /PID %PID% 2>nul if %errorlevel% equ 0 ( echo Process killed successfully ) else ( echo Failed to kill process ) ) echo. sleep 2 netstat -ano | findstr ":8000" | findstr "LISTENING" if %errorlevel% neq 0 ( echo Port 8000 is now free ) else ( echo Port 8000 still in use ) pause