Waiting for the completion of the process created by calling the batch file

MyFile1.bat calls MyFile1.bat twice:

 start MyFile2.bat argA, argB, argC start MyFile2.bat argX, argY, argZ 

At this point, how can I wait for the completion of both processes generated by the calls to MyFile2.bat ?

+8
command-line batch-file command-prompt windows-shell
source share
4 answers

Just use the Start / WAIT option.

 start /wait MyFile2.bat argA, argB, argC start /wait MyFile2.bat argX, argY, argZ 
+7
source share
 start /w cmd /c "start cmd /c MyFile2.bat argA, argB, argC & start cmd /c MyFile2.bat argA, argB, argCt" 

According to my tests, this should work, provided that MyFile2.bat. In general, full paths to bat files should be used.

+3
source share

You can use β€œstatus files” to know this; for example, in MyFile1.bat do the following:

 echo X > activeProcess.argA start MyFile2.bat argA, argB, argC echo X > activeProcess.argX start MyFile2.bat argX, argY, argZ :waitForSpawned if exist activeProcess.* goto waitForSpawned 

And insert this line at the end of MyFile2.bat:

 del activeProcess.%1 

You can also insert a ping delay in a wait loop to waste less CPU in this loop.

+3
source share

You can do it as follows:

 start MyFile2.bat argA, argB, argC start MyFile2.bat argX, argY, argZ ^& echo.^>End.val ^& exit :testEnd if exist end.val (del end.val echo Process completed pause) >nul PING localhost -n 2 -w 1000 goto:testEnd 

When the second start start2.bat start is the task, then the file "End.val" will be created, you just need to check if this file exists, then you know that your process is completed.

If the first myfile2 may take longer and then the second, you can do the same (with a different file name) with the first start myfile2.bat and make the test larger in :testend

  start MyFile2.bat argA, argB, argC ^& echo.^>End1.val ^& exit start MyFile2.bat argX, argY, argZ ^& echo.^>End.val ^& exit :testEnd if exist end.val if exist end1.val (del end.val del end1.val echo Process completed pause) >nul PING localhost -n 2 -w 1000 goto:testEnd 
+2
source share

All Articles