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
Related videos on Youtube
Comments
-
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
-
Mat about 12 yearsgnuwin32.sourceforge.net/summary.html - you can run exactly that on Windows.
-
Marcin about 12 yearscan I pipe it through the PHP ? i.e. system() ?
-
-
phuclv over 7 yearspiping
tasklist
into other programs to grep should be avoided, just like in Linux you should usepgrep -l proc
instead ofps -A | grep proc
because it's shorter, faster (because only 1 process is spawned) and more correct (because it avoids race condition) -
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 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 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 over 5 yearsThis answer is neater than the accepted one.
/fi
also supports querying bywindowtitle
. The Wildcard only seems to work as a suffix, but if more control is needed, it's still ultimately possible to pipe tofind
as above. You can also use/fo
to format as CSV, which would be useful for processing in Powershell.