I want my batch script to run a batch script, which doesn't terminate, then run several more batch scripts, which do terminate, and then close the first batch script.
The issue is, the first batch script I start needs to establish a connection before I can start running the others, and to determine when that's done I need to watch the output of the first script I start for the string that indicates that the connection is established.
In pseudo-code,
start first script
wait for first script to output specific string
while the first script remains running:
run several other scripts
close the first script
This string will appear only after several previous lines have been printed. Both the number of lines and the time this takes can vary. The strings are not outputted all at once. I cannot modify this script.
The desired result is this:
C:\>first_batch_script.bat
Some line
Doing a thing
Winning the points
The Sims did this joke better
Connection established
certain string
C:\>other_batch_script.bat
other_batch_script is done!
C:\>another_batch_script.bat
another_batch_script is done!
C:\>REM kill first_batch_script.bat
This is the code I'm trying:
FOR /f "tokens=* delims=" %%L IN ('first_batch_script.bat ^| find "certain string"') DO echo %%L
call other_batch_script.bat
call another_base_script.bat
REM kill first_batch_script.bat
Using FOR /f
seems promising, but when I run this the batch script runs quite slowly and then seems to hang. In any event, even if it ran through, I'm not seeing a good way to then break out of the loop and continue executing my code
Using START /WAIT
doesn't help because the first script I start doesn't (and shouldn't) terminate. Using any kind of timing method just won't work because it can take fairly different amounts of time for the connection to be established.
So, long and short: