Search code examples
filebatch-fileprepare

Code to end one batch file with another-can anyone assist?


I have a small batch program i made to run a few batch files. I have it set up to run the files. Just a quick question: I have a prep file to get the files ready for the next batch file. However, the prep file runs in a loop. I made it run in a loop so i could customize it per-machine. I want it to basically loop for 10 seconds and then close. I want it so my main batch file opens the prep batch file, runs it for 10 seconds, closes it, and then runs the next batch file in the sequence. Is there any way to do this? See the example below for more. Thanks!

Example:

Launcher folder/prep.bat
@echo off
start prep.bat
//Wait for 10 seconds, then close prep.bat
start launch.bat

Solution

  • In prep.bat add this

    @Echo Off
    title Prep.bat
    

    and then in the controlling batch file add this

    start "" prep.bat
    ping -n 10 localhost >nul
    taskkill /f /im cmd.exe /fi "windowtitle eq Prep.bat"