Equivalent of ps -A | grep -c process in Windows?

38,224

Solution 1

Simple commands:

tasklist | FIND "script.php"

Solution 2

An alternative solution to the accepted answer

tasklist /fi "Imagename eq script*"

In case you need this in a loop

for /l %x in (1, 0, 2) do (timeout /t 2 | tasklist /fi "Imagename eq script*")

Source: https://technet.microsoft.com/en-us/library/bb491010.aspx

Share:
38,224

Related videos on Youtube

Marcin
Author by

Marcin

Developer

Updated on August 27, 2020

Comments

  • Marcin
    Marcin over 3 years

    I am looking for an equivalent/alternative of Linux's ps -A | grep -c script.php for ms windows ?

    cheers, /Marcin

  • phuclv
    phuclv over 7 years
    piping tasklist into other programs to grep should be avoided, just like in Linux you should use pgrep -l proc instead of ps -A | grep proc because it's shorter, faster (because only 1 process is spawned) and more correct (because it avoids race condition)
  • Abhijit Sarkar
    Abhijit Sarkar almost 7 years
    @LưuVĩnhPhúc You said what he shouldn't use, but not what he should use. Care to show that as well for completeness?
  • Abhijit Sarkar
    Abhijit Sarkar almost 7 years
    @LưuVĩnhPhúc I did, but you hadn't referred to it before, so there was no link between your comment and his answer. Besides, his isn't the accepted answer.
  • phuclv
    phuclv almost 7 years
    @AbhijitSarkar being accepted just mean that it helps the OP. It doesn't mean that it's the best way. As I said you shouldn't pipe tasklist output due to the above issues, the other answer fits the criteria and there's no reason mentioning it again in my comment
  • mwfearnley
    mwfearnley over 5 years
    This answer is neater than the accepted one. /fi also supports querying by windowtitle. The Wildcard only seems to work as a suffix, but if more control is needed, it's still ultimately possible to pipe to find as above. You can also use /fo to format as CSV, which would be useful for processing in Powershell.