Created
October 27, 2022 03:09
-
-
Save muthuishere/804ff14d3750bfb2ffaa01b9c36c79f4 to your computer and use it in GitHub Desktop.
Batch file script to free up port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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