构建 cmd 命令以从任务列表中提取 PID 并对结果使用条件

Build cmd command to extract PID from tasklist and use condition on the result

我正在尝试编写 一行 cmd 命令:

所以我已经阅读 How to extract a specific field from output of tasklist on the windows command line and used this answer 以构建此命令:

for /f "tokens=2 delims=," %F in ('tasklist /nh /fi "PID eq 5284" /fo csv') do if %F NEQ "5284" (@echo no) else  (@echo yes)

我没有得到预期的结果。很可能语法错误。

刚刚贴出eryksun评论的答案:

(for /f "tokens=2 delims=," %F in ('tasklist /nh /fo csv /fi "PID eq 5284"') do @echo yes) || @echo no