如何从Windows命令行任务列表的输出提取特定领域 [英] How to extract a specific field from output of tasklist on the windows command line
本文介绍了如何从Windows命令行任务列表的输出提取特定领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我跑在Windows下面的命令命令提示符
I ran the following command on the windows command prompt
C:>tasklist /fi "Imagename eq BitTorrent.exe"
其中的输出是
Image Name PID Session Name Session # Mem Usage
================== ======== ================= =========== =========
BitTorrent.exe 6164 Console 3 24,144K
我需要从上面的输出中提取只有一个领域,PID,即6164号
I need to extract only one field, the PID, i.e. the number 6164 from the above output.
我如何实现这一目标?
更一般地,我如何提取的一个子集从命令的Windows命令行输出上的字段(1 /更多)?
How do I achieve this ? More generally, how do I extract a subset(1/more) of the fields from the output of a command on the windows command line ?
推荐答案
要previous答案相似,但使用特定的交换机任务列表
跳过头守分在图像名称的空间,不论:
Similar to previous answers, but uses specific switches in tasklist
to skip header and behave correctly irrespective of spaces in image names:
for /f "tokens=2 delims=," %F in ('tasklist /nh /fi "imagename eq BitTorrent.exe" /fo csv') do @echo %~F
(直接从CMD线运行,如果从批处理中运行替换%F
与 %%˚F
这篇关于如何从Windows命令行任务列表的输出提取特定领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文