dimanche 29 mars 2015

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

I'm trying to write one line cmd command that:



  • execute tasklist with PID filter

  • iterate over the output

    • do something if PID found

    • do something else if PID was not found




So I've read How to extract a specific field from output of tasklist on the windows command line and used this answer to construct this command:



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)


I didn't get the expected result. Most likely got the syntax wrong.


Aucun commentaire:

Enregistrer un commentaire