-3

I want to run these 3 .bat files in loop. Tried these 2 codes and got invalid syntax error from both

@echo off
:loop
start "c:\1.bat" && "c:\2.bat" && "c:\3.bat" &&
GOTO :loop

and

@echo off
for /l %%x in (1, 1, 9999) do (
    start "c:\1.bat" && "c:\2.bat" && "c:\3.bat" &&
   set /a loopCount=%loopCount%-1
   if %loopCount%==0 GOTO:EOF
)
  • 3
    `call /?`, `goto /?` – Stephan Oct 05 '21 at 13:07
  • 1
    [How to create an infinite loop in Windows batch file?](https://stackoverflow.com/questions/5487473/how-to-create-an-infinite-loop-in-windows-batch-file) – Squashman Oct 05 '21 at 13:16
  • cmd.exe runs 1 first, after it finished then run 2 and after 2 finished then run 3, after 3 finished loops back to 1 – dawnslayer Oct 06 '21 at 20:16
  • @dawnslayer Okay. That is a classic "endless" serial processing of multiple batch files which is very easy to code. Modify the first posted batch file code by replacing the third line with three lines. The first one is `call "C:\1.bat"`, the second one is `call "C:\2.bat"` and the third one is `call "C:\3.bat"`. The batch file with the now six lines would already work as wanted by you. – Mofi Oct 08 '21 at 17:57
  • @dawnslayer But I suggest to replace also the last line `goto :loop` by the following two lines: `%SystemRoot%\System32\choice.exe /C RE /N /T 3 /D R /M "Press E to exit ..."` and `if not errorlevel 2 goto loop`. Run in a command prompt window `choice /?` for help on this command. It prompts you to press key E to exit the processing of the main batch file before starting a new batch file processing series and waits three seconds for the user input. After three seconds without a user pressed key E the processing continues automatically with a jump to the line below the label `:loop`. – Mofi Oct 08 '21 at 18:04

1 Answers1

-1

The answer is

@echo off
cd c:\
:loop
start 1.bat
start 2.bat
start 3.bat
goto loop
ahmed
  • 86
  • 5
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 12 '21 at 02:48
  • That code is complete nonsense as it results in starting instances of `cmd.exe` for processing the batch files `1.bat`, `2.bat` and `3.bat` as fast as possible in a loop until there are no resources available anymore to start one more process. – Mofi Nov 20 '21 at 12:53