Tiemout in a for loop
Posted: 08 Mar 2020 14:36
Hi there,
I looked for a solution on many forums but I didn't find any suitable ones...
I have several functions (let's say file_1.req file_2.req...file_100.req) I would like to launch with the associated program (let's say calculate.exe). A normal calculation is done within approx. 10s. For some reasons, a file_i.req may make calculate.exe get stuck and the following functions (from i+1 to n) won't be launched (idle case). To avoid this problem, I want to write a batch file which would call calculate.exe for each file_i.req and which would use a 'timeout' (let's say 15s) to perform calculations in a finite time. Moreover it would continue with a 'taskkill' for file_i.req in case 'timeout' elapsed (without waiting for user's commands). I would like my script to continue with the 'i+1' .req file's calculation.
I can not use 'start' for calculate.exe which would open n windows for each req file.
Here is my pseudo-code in the .bat file :
set enabledelayedexpansion
set beginning=file_
set extension=.req
for /L %%g in (1,1,100) do(
set file_req=%beginning%%%g%extension%
call calculate.exe -f %file_req%
:: timeout /T 15 /nobreak
:: taskkill (calculate.exe -f %file_req%)
:: continue
)
endlocal
Thanks a lot for helping !
Pierre
I looked for a solution on many forums but I didn't find any suitable ones...
I have several functions (let's say file_1.req file_2.req...file_100.req) I would like to launch with the associated program (let's say calculate.exe). A normal calculation is done within approx. 10s. For some reasons, a file_i.req may make calculate.exe get stuck and the following functions (from i+1 to n) won't be launched (idle case). To avoid this problem, I want to write a batch file which would call calculate.exe for each file_i.req and which would use a 'timeout' (let's say 15s) to perform calculations in a finite time. Moreover it would continue with a 'taskkill' for file_i.req in case 'timeout' elapsed (without waiting for user's commands). I would like my script to continue with the 'i+1' .req file's calculation.
I can not use 'start' for calculate.exe which would open n windows for each req file.
Here is my pseudo-code in the .bat file :
set enabledelayedexpansion
set beginning=file_
set extension=.req
for /L %%g in (1,1,100) do(
set file_req=%beginning%%%g%extension%
call calculate.exe -f %file_req%
:: timeout /T 15 /nobreak
:: taskkill (calculate.exe -f %file_req%)
:: continue
)
endlocal
Thanks a lot for helping !
Pierre