Doctor Who
Doctor Who

Reputation: 1659

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?

Upvotes: 0

Views: 123

Answers (2)

Aacini
Aacini

Reputation: 67216

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

Upvotes: 0

MC ND
MC ND

Reputation: 70933

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.

Upvotes: 1

Related Questions