簡體   English   中英

用於在具有計數的文件夾中執行 all.exe 的批處理文件

[英]Batch File to execute all .exe in a folder with count

我有很多exe文件,我想用一個批處理文件運行它們。 據我了解,這兩個代碼對我有用;

for %%a in ("\*.exe") do start "" "%%\~fa"

for %%i in (\*.exe) do start "" /b "%%i"

但是當所有文件運行時, cmd屏幕關閉。 我想要的是:進程完成后cmd屏幕不會關閉,並會顯示結果(如果可能的話會計算),一個可以計算這些 .exe 文件中有多少工作正常以及有多少失敗的代碼。

例如; 87 個文件被阻止 13 個文件無法被阻止 類似這樣的事情? 這可能嗎?

也許您可以從下面的這批產品中獲得靈感。 它通過程序退出代碼工作。 它生成所有可執行文件,等待它們完成,然后計算失敗/成功的數量。 它還應該與設計良好的 GUI 程序一起使用,而不僅僅是基於命令行的程序。

這是一個粗略/基本的答案,您可能需要根據您的具體需要對其進行完善。

@echo off
setlocal enableextensions enabledelayedexpansion

REM Use marker files for getting results.
set OK_EXT=.SUCCESS
set FAIL_EXT=.FAILURE

REM Purge all possible marker files.
del /q *!OK_EXT! *!FAIL_EXT! > NUL 2>&1
set /a count=0
REM Parse all executables
for %%E in (*.exe) do (
    echo Launching: %%~nxE
    REM Create two marker files for each executable.
    echo.>%%~nE!OK_EXT!
    echo.>%%~nE!FAIL_EXT!
    REM Start the executable, delete the WRONG marker.
    REM I would have prefered to use "touch" to create the good one instead, but not standard on Windows.
    start %comspec% /C "%%~nxE && ( del /q %%~nE!FAIL_EXT! ) || ( del /q %%~nE!OK_EXT! )"
    set /a count +=1
)
REM Now, "count" contains the number of executables launched.
echo All processes launched.
echo.
:loop
echo Waiting for results...
set /a curr=0
REM Simply count the number of marker files. Must be equal to "count" when everything is finished.
for /F "usebackq tokens=*" %%C in (`dir /b *!OK_EXT! *!FAIL_EXT!`) do (
    set /A curr+=1
)
if !curr! GTR !count! (
    set /a curr-=!count!
    echo    Still !curr! processes running...
    timeout /t 2
    goto :loop
)
echo All results found.
echo.
echo Parsing results...
set /a ok_exe=0
set ok_exe_list=
set /a fail_exe=0
set fail_exe_list=
REM Parse all marker files.
for /F "usebackq tokens=*" %%C in (`dir /b *!OK_EXT! *!FAIL_EXT!`) do (
    REM And set counters + list according to the marker file type (OK or FAILED).
    if /I "%%~xC"=="!OK_EXT!" (
        set /A ok_exe+=1
        set ok_exe_list=!ok_exe_list! %%~nC
    ) else (
        set /A fail_exe+=1
        set fail_exe_list=!fail_exe_list! %%~nC
    )
)
REM Simple display.
echo Programs without error: !ok_exe!/!count!
echo    !ok_exe_list!
echo.
echo Programs with error: !fail_exe!/!count!
echo    !fail_exe_list!
echo.
goto :eof

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM