简体   繁体   中英

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

如果您只是想知道一个程序正在运行多少实例,请使用FIND命令的计数功能。

FOR /F "delims=" %%G IN ('tasklist ^|find /I /C "ruby.exe"') do set count=%%G

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM