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

css - I want to align grid in center -

Contact Form PHP Email Script -

python - SWIG function not printing output -