【问题标题】:Build cmd command to extract PID from tasklist and use condition on the result构建 cmd 命令以从任务列表中提取 PID 并在结果上使用条件
【发布时间】:2015-06-02 12:08:28
【问题描述】:

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

  • 使用 PID 过滤器执行 tasklist
  • 迭代输出
    • 如果找到 PID 就做点什么
    • 如果找不到 PID,请执行其他操作

所以我已经阅读了How to extract a specific field from output of tasklist on the windows command line 并使用了这个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)

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

【问题讨论】:

  • 只有当 PID 5284 存在时才会执行循环的命令。试试这个:(for /f "tokens=2 delims=," %F in ('tasklist /nh /fo csv /fi "PID eq 5284"') do @echo yes) || @echo no.
  • @eryksun 太好了。发布答案,我会接受。 10x

标签: windows cmd tasklist


【解决方案1】:

刚刚发布了eryksun评论的答案:

(for /f "tokens=2 delims=," %F in ('tasklist /nh /fo csv /fi "PID eq 5284"') 做@echo 是)|| @echo 没有

【讨论】:

    猜你喜欢
    • 2015-01-17
    • 1970-01-01
    • 1970-01-01
    • 2014-08-30
    • 2012-03-20
    • 2012-03-31
    • 2018-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多