How to extract a specific field from output of tasklist on the windows command line

后端 未结 3 2020
难免孤独
难免孤独 2020-12-14 21:08

I ran the following command on the windows command prompt

C:>tasklist /fi \"Imagename eq BitTorrent.exe\"

The output of which is

3条回答
  •  独厮守ぢ
    2020-12-14 21:46

    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
    

    (as run directly from cmd line, if run from batch replace %F with %%F

提交回复
热议问题