1

I want to find process with title containing some string and pass it's PID to taskkill, but I can't find proper syntax, can somebody tell what is wrong with this line?

C:\>cmd /c for /f "tokens=2 delims=," %a in 
('tasklist /v /fo:csv /nh | findstr /r /c:"1234"') do taskkill /f /pid %a

Result:

FINDSTR: Cannot open do
FINDSTR: Cannot open taskkill
FINDSTR: Cannot open /f
FINDSTR: Cannot open /pid
FINDSTR: Cannot open %a

1 Answers1

2

I was able to get this to work by escaping the pipe symbol. To use the cmd /c syntax, I had to wrap the whole thing in quotes as well.

cmd /c "for /f "tokens=2 delims=," %a in ('tasklist /v /fo:csv /nh ^| findstr /r /c:"1234"') do taskkill /f /pid %a"

This link proved helpful in arriving at the resolution.

CaseyR
  • 136
  • 3