我想找到标题包含某些字符串的进程并将其 PID 传递给 taskkill,但我找不到正确的语法,有人能说出这一行有什么问题吗?
C:\>cmd /c for /f "tokens=2 delims=," %a in
('tasklist /v /fo:csv /nh | findstr /r /c:"1234"') do taskkill /f /pid %a
结果:
FINDSTR: Cannot open do
FINDSTR: Cannot open taskkill
FINDSTR: Cannot open /f
FINDSTR: Cannot open /pid
FINDSTR: Cannot open %a
答案1
我可以通过转义管道符号来实现这一点。要使用该cmd /c
语法,我还必须将整个内容括在引号中。
cmd /c "for /f "tokens=2 delims=," %a in ('tasklist /v /fo:csv /nh ^| findstr /r /c:"1234"') do taskkill /f /pid %a"
这关联对达成决议很有帮助。