3

Need to check if the process is running and the port that is being used(8086 and 8085) is in listening state, using a batch file

Rahul
  • 76,197
  • 13
  • 71
  • 125

2 Answers2

5
netstat /o /a | find /i "listening" | find ":8086" >nul 2>nul && (
   echo 8086 is open
) || (
  echo 8086 is Not open
)
npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • 1
    Thanks i did with findstr netstat -o -n -a | findstr 8086 if %ERRORLEVEL% equ 0 goto FOUND echo port not found goto FIN :FOUND echo port found :FIN Note: When an item is not found FINDSTR will return an %ERRORLEVEL% > 0 if item is found FINDSTR will return an %ERRORLEVEL% = 0 – Tanuja kurkute Oct 31 '17 at 12:32
  • 3
    Also as a one-liner which is useful sometimes netstat -nao | findstr "LISTENING" | findstr "0:8086" >nul 2>nul && (echo Port 8086 is open) || (echo Port 8086 is closed && exit 1) Note the "exit 1" which returns an %ERRORLEVEL% > 0 – posix99 Jun 27 '18 at 13:12
1
netstat -o -n -a | findstr 8086

if %ERRORLEVEL% equ 0 goto FOUND

echo port not found

goto FIN

:FOUND

echo port found

:FIN

Note: When an item is not found FINDSTR will return an %ERRORLEVEL% > 0 if item is found FINDSTR will return an %ERRORLEVEL% = 0

npocmaka
  • 55,367
  • 18
  • 148
  • 187