how to send each iteration of a loop in a batch script to a new cmd window and continue with loop

StackOverflow https://stackoverflow.com/questions/23496663

  •  16-07-2023
  •  | 
  •  

Question

Disclaimer: I'm an engineer not a programmer, so while I do have technical knowledge, please bear with me if I am using the wrong terminology or asking the wrong questions.

I am trying to write a windows batch script that will allow me to submit multiple finite element simulations as a batch with all of the same settings. I currently have a script that works after a fashion, but it is not as efficient as I would like. My current script steps through the directories and runs the simulation in the command window before moving on to the next directory and repeating the loop. This script can be seen below:

@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

title BEST FRM Runs batch submission

echo This script will step through the run# directories and run the blast.k file in each run# folder.  The .cmd file needs to be placed in the "FRMRuns" directory.  You may  need to change the reference to the LSDYNA solver if the version has changed.

SET /P ANSWER=Do you want to continue (y/n)?
if /i {%ANSWER%}=={y} (goto :yes)
if /i {%ANSWER%}=={n} (goto :no)

:yes
SET /P i=Enter input file name (e.g blast.k)
SET /P n=Enter number of CPUs (e.g. 2)
SET /P m=Enter memory (e.g 500m)
FOR /D %%D IN (run*) DO (
echo %%D
cd %%D
set lstc_license=network
set lstc_license_server=###.##.##.##
::the solver reference may need to be changed as we move on to new versions
c:\LSDYNA\program\ls971_s_R5.1.1_winx64_p.exe i=%i% ncpu=%n% memory=%m%
cd ..
)
exit /b

:no
exit /b

Our network licensing for LSDYNA allows for queuing of jobs, so ideally I would like to run through the entire loop and have the jobs run simultaneously rather than run one after another. I think this would be possible if I could send each iteration of the loop to a new command window and have it execute independently while the loop in batch script continues.

I'm not sure if I am searching for the wrong things, or if this is a unique request, but I have not been able to find anything that really helps with what I am trying to do. I have tried various things using start /b cmd /k, but I have not been able to pass the loop commands to the new window and have the loop continue in the original window. I have managed to get the new window to open, but not to actually execute any commands, and the code does not continue until the new window is closed.

I would appreciate any suggestions that you might have for how to accomplish my goal.

Thank you!

Was it helpful?

Solution

This starts each command in it's own process, with the start "" at the beginning.

start "" c:\LSDYNA\program\ls971_s_R5.1.1_winx64_p.exe i=%i% ncpu=%n% memory=%m%
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top