Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: batch file multiple instances  (Read 3938 times)

0 Members and 1 Guest are viewing this topic.

stathis

    Topic Starter


    Starter

    • Experience: Experienced
    • OS: Windows 8
    batch file multiple instances
    « on: April 27, 2015, 10:49:34 AM »
    Hey everyone. I need help with something.
    I have a batch file batch.bat that runs after a torrent finishes performing some standardized routines.

    Sometimes it happens, while batch file is still running, that another torrent finishes and batch.bat is triggered again, messing everything up. What is want it to check if batch.bat is still running, then wait to finish and continue with the new instance of batch.bat

    Can we do something like this?

    Thanks for the help!!

    DaveLembke



      Sage
    • Thanked: 662
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: batch file multiple instances
    « Reply #1 on: April 27, 2015, 11:04:50 AM »
    If running multiple instances of same batch, its best to have say if your running 4 downloads at the same time a file called batch1, batch2, batch3, and batch4. So that the naming of one of the same code batches doesnt conflict with the other. I use this name_numbering all the time when running automation that looks for instances open or closed etc as well as taskkill routines where you want to specifically kill a process, but the PID is random and you need to kill it by name.

    batch1.bat
    batch2.bat
    batch3.bat
    batch4.bat

    should fix this

    stathis

      Topic Starter


      Starter

      • Experience: Experienced
      • OS: Windows 8
      Re: batch file multiple instances
      « Reply #2 on: April 27, 2015, 11:18:56 AM »
      I thought of that. Problem though is that utorrent in this case has the "Run Program" option to Run this program when a torrent finishes allowing only 1 file, so the naming scheme you suggest cannot work here

      DaveLembke



        Sage
      • Thanked: 662
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: batch file multiple instances
      « Reply #3 on: April 27, 2015, 11:25:41 AM »
      Ok... you could install other copies of uTorrent to custom install locations and run multiples of it with single download each instance, and each instance has its own unique batch file name.

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10

      Lemonilla



        Apprentice

      • "Too sweet"
      • Thanked: 70
      • Computer: Specs
      • Experience: Experienced
      • OS: Windows 7
      Re: batch file multiple instances
      « Reply #5 on: April 27, 2015, 11:55:54 AM »
      Code: [Select]
      start /b cmd /c %~0 2>nul 1>&2Assuming I haven't forgotten a crucial part, this will open a new instance of the saved batch file in the background of the current file.  They will share the same output console, and It's very complicated to stop them, but thats how you thread.  I would recommend going with the above answer and doing something like
      Code: [Select]
      for %%A in (1,1,4) do start batch.bat
      Which should open 4 separate instances of batch.bat.

      Do a search for snake.bat on this site, (it's a link to a different forum) as an example of how it works.
      Quote from: patio
      God Bless the DOS Helpers...
      Quote
      If it compiles, send the files.