Skip to content

Instantly share code, notes, and snippets.

@muthuishere
Created October 27, 2022 03:09
Show Gist options
  • Save muthuishere/804ff14d3750bfb2ffaa01b9c36c79f4 to your computer and use it in GitHub Desktop.
Save muthuishere/804ff14d3750bfb2ffaa01b9c36c79f4 to your computer and use it in GitHub Desktop.
Batch file script to free up port
@echo off
set PORT_NUMBER= 8080
netstat -a -n -o | findstr %PORT_NUMBER% > tmpFile
set /p input= < tmpFile
del tmpFile
set PROCESS_ID_INDEX=5
for /F "tokens=%PROCESS_ID_INDEX% delims= " %%a in ("%input%") do set PROCESS_ID=%%a
IF "%PROCESS_ID%" == "" GOTO :NO_PROCESS
echo %PROCESS_ID%
taskkill /f /pid %PROCESS_ID%
GOTO :EXIT
:NO_PROCESS
echo "Port %PORT_NUMBER% is free already"
:EXIT
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment