I'm using tasklist command.
I'm trying to use the /fi option to filter multiple PIDs.
tasklist.exe /v /fi "PID eq 3248" /fi "PID eq 9488"
INFO: No tasks are running which match the specified criteria.
This doesn't work. I can only assume the filters are evaluated internally using logical-and and obviously would never be true.
How to filter by multiple PIDs?
If I run it separately, the result are OK and I can set the process information. However,
tasklist.exe /v /fi "PID eq 3248"tasklist.exe /v /fi "PID eq 9488"I'd like to refrain activating two separate commands.
use find
tasklist.exe /v | find /i "9488"
Which brings the questions:
tasklist is not able to filter to several PIDs. So use full output and use another method to filter:
use csv as output format; PID is token2, windowtitle is token9.findstr is able to search for more than one string (separated by spaces here)./x checks "complete line", so 45 would not match 3456.>nul supresses output of findstr (we need only the errorlevel, not the actual output)&& acts as "if previous command (findstr) was successful, then..."
@echo off
for /f "tokens=2,9 delims=," %%a in ('tasklist /v /fo csv') do (
echo %%~a|findstr /x "3248 9488" >nul && echo %%~a %%~b
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With