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
Tiemout in a for loop
Moderator: DosItHelp
Re: Tiemout in a for loop
At least you have to use the START command (perhaps START /B) to run your tool asynchronously. Otherwise the timeout command would not be called before calculate.exe has finished.
Untested:
Code: Select all
set "beginning=file_"
set "extension=.req"
for /L %%g in (1,1,100) do(
start /b calculate.exe -f "%beginning%%%g%extension%"
timeout /t 15 /nobreak
taskkill /im calculate.exe /f
)
Steffen
Re: Tiemout in a for loop
In your original code, there are some commands that will prevent a correct functioning.
Note: just for a learning purpose; I would go with @aGerman's code.
set enabledelayedexpansion should be:
(setlocal /? or details)
call calculate.exe -f %file_req% should be:
( SET /? for details )
Note:
In aGerman's solution, you might want to try
This will wait until the calculate.exe process is ended. That way you can skip the timeout command.
(start /? for details)
Note: just for a learning purpose; I would go with @aGerman's code.
set enabledelayedexpansion should be:
Code: Select all
setlocal enabledelayedexpansion
call calculate.exe -f %file_req% should be:
Code: Select all
call calculate.exe -f !file_req!
Note:
In aGerman's solution, you might want to try
Code: Select all
start /wait "Dummy title" calculate.exe -f "%beginning%%%g%extension%"
(start /? for details)
Re: Tiemout in a for loop
Hi Eureka,
You are right. It launches calculate.exe for every file_i.req and it passes through idle ones indeed.
Even if it does use the 'timeout' command, your code is running well !
Thank you very much !
Thanks to German too !
Pierre
You are right. It launches calculate.exe for every file_i.req and it passes through idle ones indeed.
Even if it does use the 'timeout' command, your code is running well !
Thank you very much !
Thanks to German too !
Pierre