
已解決bat腳本中如何顯示正在運行的程序數(shù)量最后由 xfgc 于 -4-25 15:49各位大佬們,想咨詢一下,bat是否能實現(xiàn)如下功能,1.計算正在運行的特定程序的數(shù)量;2.當運行程序的數(shù)量小于某一值(比如 40 )時,自動運行下一個程序,直到滿足運行程序的數(shù)量為40
nclick="copycode($('code0'));">復制代碼
- @echo off
- setlocal enabledelayedexpansion
- call fds
- set filnavn1=1.fds
- set mappenavn1=1
- set path1=%mappenavn1%
- set filnavn2=2.fds
- set mappenavn2=2
- set path2=%mappenavn2%
- set filnavn3=3.fds
- set mappenavn3=3
- set path3=%mappenavn3%
- set filnavn4=4.fds
- set mappenavn4=4
- set path4=%mappenavn4%
- if not exist %path1% mkdir %path1%
- copy %filnavn1% %path1%
- if not exist %path2% mkdir %path2%
- copy %filnavn2% %path2%
- if not exist %path3% mkdir %path3%
- copy %filnavn3% %path3%
- if not exist %path4% mkdir %path4%
- copy %filnavn4% %path4%
- cd %mappenavn1%
- start cmd /k call fds_local -p 4 %filnavn1%
- cd..
- cd %mappenavn2%
- start cmd /k call fds_local -p 4 %filnavn2%
- cd..
- rem 定義包含 fds 文件的文件夾列表
- set folders=Folder1 Folder2 Folder3 Folder4
- REM 設置特定程序名稱
- set program_name=fds.exe
- REM 設置計數(shù)器
- set /a count=0
- REM 遍歷 tasklist 輸出的每一行
- for /f skip=3 tokens=1 %%a in ('tasklist ^| findstr /i /c:%program_name%') do (
- REM 如果行不為空,則增加計數(shù)器
- if not %%a== (
- set /a count+=1
- )
- )
- REM 如果特定程序的數(shù)量小于8,則啟動下一個程序
- if %count% LSS 8 (
- rem 獲取下一個未運行的 fds 文件
- for %%i in (%folders%) do (
- cd %%i
- for %%j in (%fds_files%) do (
- tasklist| findstr /i fds.exe > nul
- if errorlevel 1 (
- rem 啟動下一個 fds 文件任務
- start cmd /c call fds_local -p 4 %%i.fds
- goto :next_file
- )
- )
- cd ..
- )
- )
- :next_file
- rem 等待一段時間后繼續(xù)檢查
- timeout /t 5
- goto start
- rem 如果沒有正在運行的 fds,則顯示 All simulations completed. 并暫停腳本
- echo All simulations completed.
- pause
- exit

