How to loop a software using batch file


  1. Posts : 241
    Windows 10 Pro
       #1

    How to loop a software using batch file


    Hi,

    I have a software that runs from command line, and it needs 2 command windows to run in parallel.

    So I use a .bat file to start both commands using START.

    Something like:
    START program.exe -m method1
    START program.exe -m method2

    One method runs for 10 hours and the other for 11 hours, then each batch command window closes.
    How can I run both methods in loops instead of having to restart each manually?

    Edit: since they do not end in the same time, I'm waiting for the second method to end and then I start both together, but then there's a time when the first method is not running because it ends earlier, although it needs to keep running immediately when it finishes

    Thanks
    Last edited by mibaup; 15 May 2021 at 00:39.
      My Computer


  2. Posts : 42,984
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #2

    Hi, personally I'd turn to Autohotkey (free) which provides extensive syntax for loops, tests, conditional structures and can interact with processes running under Windows.
      My Computers


  3. Posts : 31,651
    10 Home x64 (22H2) (10 Pro on 2nd pc)
       #3

    Liargoff said:
    So I use a .bat file to start both commands using START.

    Something like:
    START program.exe -m method1
    START program.exe -m method2

    One method runs for 10 hours and the other for 11 hours, then each batch command window closes.
    How can I run both methods in loops instead of having to restart each manually?
    To loop a batch file forever add a label at the beginning and a GOTO at the end. START has a /WAIT option, so you can wait for the longer of the two methods to complete before looping back to the beginning. Something like....

    :Begin
    START program.exe -m method1
    START /WAIT program.exe -m method2
    GOTO Begin
      My Computers


  4. Posts : 456
    Windows 10
       #4

    You can pharse the processes list in loop to check like every 30 seconds if both processes are running and if not your restart them.
      My Computer


  5. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #5

    Hello @Bree,

    Bree said:
    To loop a batch file forever add a label at the beginning and a GOTO at the end. START has a /WAIT option, so you can wait for the longer of the two methods to complete before looping back to the beginning. Something like....

    :Begin
    START program.exe -m method1
    START /WAIT program.exe -m method2
    GOTO Begin

    I run a list of Commands in a Batch Script, and on one particular one [ CCleaner ], I wanted to get it to wait to finish before continuing, so I timed the duration that it ran and then added a quarter of the time, and ended up with this . . .

    Code:
    
    cd %ProgramFiles%\CCleaner & Start CCleaner64.exe /auto
    timeout /t 20 /nobreak >nul
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 09:28.
Find Us




Windows 10 Forums