简体   繁体   中英

batch file: detect when 2nd command prompt closes?

I'm using a batch file to run a bunch of selenium automation through maven.

When the automation starts it opens a new command prompt to run the maven command:

start cmd /c mvn site surefire-report:report -Dtest=uk.co.......

When the maven command prompt closes I then ask the person that's running it to press 1 in the main command prompt so it can copy the test results to a shared location.

Sometimes people are forgetting to press 1 and just closing everything so it fails to copy, I was wondering if there is a way I can detect when the maven command prompt closes and then automatically copy the results?

start "" /wait cmd /c mvn site surefire-report:report -Dtest=uk.co.......

Or if the new cmd window is not needed, directly call cmd /c .... or, if mvn is a batch file, use call mvn ....

In any of the cases, the caller will stop its execution until the called process ends.

You may use a file to indicate that maven command is active: create the file before run maven command and delete it when maven ends. In the main program, enter a wait cycle until the indicator file disappear:

rem Create the indicator file:
echo X > mavenActive.txt

rem Start maven and delete the indicator file at end:
start cmd /c mvn site surefire-report:report -Dtest=uk.co....... ^& del mavenActive.txt

rem Wait for the indicator file disappear:
:wait
   rem Insert a delay so not use too much cpu:
   timeout /t 20 /nobreak
if exist mavenActive.txt goto wait

rem Copy maven results here:
copy ...

If there are several simultaneous maven processes, you may use a different number for each indicator file and then wait for all of them with if exist mavenActive*.txt goto wait

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM