Page 1 of 1

Batch script that runs batchscripts

Posted: 26 Mar 2021 14:05
by StructuralMech
Hello fellows,

Ive got the following problem:
For my masters thesis in structural engineering Im doing FE-analyses. The Programm Im supposed to work with isnt that well programmed and i cannot make a qeue of several calculations - like over night calculation to safe time.
The calculations can be run as a batch file in console and in every subfolder of the different models there is a file called run_inp_in_AtenaConsole.bat. So I decided to write a batch skript that runs the different calculation.bat files in a row.
The skript currently looks like that and it works:

Code: Select all

@echo off
:: EF is the first subfolder
cd EF1
echo %cd%
:: the second subfoler with the batch included
cd DF26_test.gid
echo %cd%
:: the file to run
start run_inp_in_AtenaConsole.bat
:: the loop it to check the n calculation is running else ( start calculation n+1); timeout 5 is to make sure the data is running; timeloop checks every timespan if the n´th calculation is running.
timeout 5
:timeloop 
timeout 30
tasklist /FI "IMAGENAME eq AtenaConsole64.exe" 2>NUL | find /I /N "AtenaConsole64.exe">NUL
if "%ERRORLEVEL%"=="0" goto :timeloop
:: next calculation
cd ../
cd DF26_test2.gid
echo %cd%
start run_inp_in_AtenaConsole.bat
::loop this till all calculations are done
I want to do this a bit more elegant for further users of this programm. to erase the input of the directories
I wrote a script that puts out the pathes of all run_inp_in_AtenaConsole.bat files. since they have all the same name it was easy using this:

Code: Select all

@echo off
setlocal
::this is the folder every calulation is into
cd E:\Atena\ATENA\GiD
echo Files Paths :
dir /b run_inp_in_AtenaConsole.bat /s> listing.txt
endlocal
Now i want to combine both scripts to make sure that the batch runs all "run_inp_in_AtenaConsole.bat" files in every subfoler in a row.

Since Im a civil engineer im not the best programmer and i would be very happy if u guys could help me.

Thank u so much in advance.

Re: Batch script that runs batchscripts

Posted: 26 Mar 2021 14:32
by Squashman
You have way over complicated this. You don't need to sit there and check if the program you just executed is still running before running the next.

Replace all of this.

Code: Select all

:: the file to run
start run_inp_in_AtenaConsole.bat
:: the loop it to check the n calculation is running else ( start calculation n+1); timeout 5 is to make sure the data is running; timeloop checks every timespan if the n´th calculation is running.
timeout 5
:timeloop 
timeout 30
tasklist /FI "IMAGENAME eq AtenaConsole64.exe" 2>NUL | find /I /N "AtenaConsole64.exe">NUL
if "%ERRORLEVEL%"=="0" goto :timeloop
:: next calculation
cd ../
cd DF26_test2.gid
echo %cd%
start run_inp_in_AtenaConsole.bat
::loop this till all calculations are done
With this

Code: Select all

:: the file to run
CALL run_inp_in_AtenaConsole.bat
:: next calculation
cd ../
cd DF26_test2.gid
echo %cd%
CALL run_inp_in_AtenaConsole.bat
::loop this till all calculations are done