Q:

count number of (pid) variables in an array?

I'm trying to count the number of ruby scripts I am running in a batch script.
I can get the script to list the numbers, but how do I count them.  Ideally, I would receive an alert when the number of PIDs has decreased.  
Thank you!
@Echo off & SetLocal EnableDelayedExpansion
set "RUBY="
for /f "tokens=2" %%A in ('tasklist ^| findstr /i "ruby.exe" 2^>NUL') do 
@Set "PID=!PID!,%%A"
if defined PID Echo cmd.exe has PID(s) %PID:~1%
echo ${#PID[@]}
pause

A:

If you just want to know how many instances of a program is running then use the count functionality of the FIND command.
FOR /F "delims=" %%G IN ('tasklist ^|find /I /C "ruby.exe"') do set count=%%G

