0

I'm having trouble figuring out the logic behind this. I have 11 .cmd files that need to run in a certain order. 5 of them can start simultaneously, the next 5 are directly dependent on the corresponding of the first five, and the last file is dependent on the second set of five to be run.

Image of workflow:
IMAGE OF WORKFLOW

  • Step 1 is to start QAQC processes 1-5.
  • Step 2 is to start the corresponding CONVERT processes for each QAQC process as it finishes.
  • Step 3 is to merge all outputs once all 5 CONVERT processes are finished.

I imagine I need to make a .cmd or .bat file for each and then call the 5 files in one file.

file1.cmd:

 call QAQC1
 call CONVERT1

file2.cmd:

call QAQC2
call CONVERT2

and so on...

And the final file would be something like:

FINAL_FINAL.cmd:

start "QAQC1.cmd" QAQC1.cmd
start "QAQC2.cmd" QAQC2.cmd
start "QAQC3.cmd" QAQC3.cmd
start "QAQC4.cmd" QAQC4.cmd
start "QAQC5.cmd" QAQC5.cmd 

I'm still unclear if this is correct or how I would make all of these steps finish before I make a call to the final file that merges everything together and requires all 10 other files to complete. Any help would be greatly appreciated!

aschipfl
  • 33,626
  • 12
  • 54
  • 99
John
  • 111
  • 4
  • Is it true that step 2 (`CONVERT`) has to wait until step 1 (`QAQC`) is completed, meaning that all five `QAQC` processes have to be finished before the first `CONVERT` process begins? Also am I wondering how you pass data from the `QAQC` steps to the `CONVERT` steps… – aschipfl May 27 '20 at 21:06
  • Perhaps it would be possible to use one batch file `QAQC` and to configure it using five different sets of command line arguments rather than five similar files, given that then intrinsic function is the same for all `QAQC` processes, and the same for `CONVERT`… – aschipfl May 27 '20 at 21:07
  • Perhaps this thread deals with a quite similar situation: [Start multiple tasks in parallel and wait for them in windows?](https://stackoverflow.com/q/49050611) – aschipfl May 27 '20 at 21:15
  • @aschipfl - Not all QAQC processes have to finish before the first CONVERT process. Just the corresponding one. So if QAQC3 finishes before QAQC1 or QAQC2, then CONVERT 3 can run. Each CONVERT step is only dependent on its corresponding QAQC step. All QAQC processes can begin simultaneously. Data is written out to a feature class at each step for both record keeping purposes and to send data back to original owner (and because my boss requested it this way). The red lines show each steps dependency. – John May 28 '20 at 18:27

1 Answers1

0
@echo off
setlocal enabledelayedexpansion
for /l %%a in (1,1,5) do (
  set /a x=!random! %% 10
  >QAQC%%a.cmd (
    echo @echo QAQC%%a
    echo @timeout !x!
  )
  >CONVERT!%%a.cmd (
    echo @echo CONVERT%%a
    echo @timeout !x!
  )
)
echo @echo merge running >merge.cmd
echo @timeout 3 >>merge.cmd
REM ignore anything before this line; it just creates a test environment

@echo off
echo wait for qaqcX and convertX to finish...
( start cmd /c "qaqc1.cmd & convert1.cmd"
  start cmd /c "qaqc2.cmd & convert2.cmd"
  start cmd /c "qaqc3.cmd & convert3.cmd"
  start cmd /c "qaqc4.cmd & convert4.cmd"
  start cmd /c "qaqc5.cmd & convert5.cmd"
) | pause >nul
call merge.cmd
echo done.
Stephan
  • 53,940
  • 10
  • 58
  • 91
  • Can you explain the first section to me? What exactly is it doing? I ran the code without it and it ran just the same, is it necessary? Either way, this worked perfectly. Thank you!!! – John Jun 01 '20 at 18:23
  • The part before the `REM`? It just generates some fake `QAQC*.cmd` and `convert*.cmd` files plus a fake `merge.cmd` to have something to run. – Stephan Jun 01 '20 at 18:27