batch file - Search for and kill PIDs, one at a time -


i have following command works pretty well:

for /f "tokens=5 delims= " %%p in ('netstat -a -n -o ^| grep :7010') taskkill.exe /pid %%p /f 

the issue is, if same port found multiple times same pid, script returns errno 1 because attempts kill pid after first have failed.

is there way modify above attempts kill pid once?

this might work you:

@echo off &setlocal disabledelayedexpansion /f "tokens=5 delims= " %%p in ('netstat -a -n -o ^| grep :7010') (     if not defined pid.%%p (         taskkill.exe /pid %%p /f         set "pid.%%p=7"     ) ) 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -