1

I m using logical operators and tasklist command in a single sentence but it is not working. My batch script:

tasklist \fi"memusage gt 18000" && \fi"memusage lt 19000"

Can anyone help me out?

Thomas
  • 4,225
  • 5
  • 23
  • 28
Akash
  • 11
  • 2

1 Answers1

4
::       ↓                          ↓
tasklist /fi "memusage gt 18000"    /fi "memusage lt 19000"
::          ↑                    ↑↑    ↑   

Explanation (see tasklist /? output):

  •   use /FI (solidus) instead of \FI (reverse solidus);
  •   separate /FI switch from filter itself using a space;
  • ↑↑ simply concatenated filters mean logical AND (cf. the last example in tasklist /?).

BTW, && operator means Conditional Execution on command level only.

JosefZ
  • 1,564
  • 1
  • 10
  • 18
  • Can you use an OR filter? This works, but it may use more CPU since it runs command twice: `tasklist /FI "IMAGENAME eq notepad.exe" & tasklist /FI "IMAGENAME eq notepad++.exe"` – gregg Oct 12 '20 at 21:39
  • 1
    @gregg Consecutive applying several filters is the only way of `OR`, AFAIK. I'd switch to PowerShell `Get-Process ` (the `-Name ` parameter allows very powerful combination of wildcards in names). You can type multiple process names (separated by commas) and use wildcard characters. Example `Get-Process -Name 'pspad','note*'` returns info for processes `notepad`, `notepad++` and `PSPad`. – JosefZ Oct 13 '20 at 10:02