I have Windows 10 and inside of my batch file I do the following:
start cmd /k "Build_x1.bat"
start cmd /k "Build_x2.bat"
start cmd /k "Build_x3.bat"
...
start cmd /k "Build_xN.bat"
The reason that I have it as start cmd
is because I want it to open in a new window; they all finish at different times and in their own window, they output their own warnings and errors of files they are compiling. As they finish, they produce a .adb file to my directory. In this same script, I want to xcopy the *.adb into a different directory. The problem I am running into is that I don't know how to start the xcopy only after all of the above cmd's finish in their own window. So I want:
start cmd /k "Build_x1.bat"
start cmd /k "Build_x2.bat"
start cmd /k "Build_x3.bat"
...
start cmd /k "Build_xN.bat"
xcopy /s/y *.adb "C:\*some directory*"
but xcopy only after all of the above start cmd
have finished. Any thoughts on how I could achieve this? I've tried a few methods but all have failed and prematurely try to copy files without them being ready.
Start them with a title and check for their windows. Loop until they all are finished:
start "MyTitle" cmd /c "Build_x1.bat"
start "MyTitle" cmd /c "Build_x2.bat"
start "MyTitle" cmd /c "Build_x3.bat"
...
start "MyTitle" cmd /c "Build_xN.bat"
:loop
timeout 1
tasklist /fi "WindowTitle eq MyTitle" |find "cmd.exe" && goto :loop
echo all of them are finished
PS: if those batch file names are like in your example, you can start them with:
for /l %%i in (1,1,%n%) do start "MyTitle" cmd /c "Build_x%%i.bat"
NOTE: cmd /k
keeps the windows open, so you will have to manually close each of them.