Bill Software Engineer
Bill Software Engineer

Reputation: 7782

In BAT file, how do I start jmeter then wait for it to finish?

I'm using window bat file to start JMeter in command line mode, running a test, and print some results. My bat file isn't waiting for jmeter to finish so it's printing empty results. Is there any way to wait for JMeter to finish first?

My bat file:

@echo off
setlocal

set "CURRENT_DIR=%cd%"
if not "%JMETER_HOME%" == "" goto gotHome
set "JMETER_HOME=%CURRENT_DIR%"
if exist "%JMETER_HOME%\bin\jmeter.bat" goto okHome
cd ..
set "JMETER_HOME=%cd%"
cd "%CURRENT_DIR%"
:gotHome

if exist "%JMETER_HOME%\bin\jmeter.bat" goto okHome
echo The JMETER_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome

break>jmeter.log
SET /P "TestFile=Test File:" || SET "TestFile=MyTestFile.txt"
echo Running test %TestFile%
start /B %JMETER_HOME%/bin/jmeter -n -t GenericTest.jmx -JTestDir="%cd%" -JTestFile="%TestFile%"
echo Test Finished, Printing Result
type result.txt
:end
pause

Running file output:

Test File:
Running test MyTestFile.txt
Test Finished, Printing Result

Press any key to continue . . . Creating summariser <summary>
Created the tree successfully using ConversationTestGeneric.jmx
Starting the test @ Tue Oct 23 19:32:11 PDT 2018 (1540348331395)
Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445
summary +     16 in 00:00:23 =    0.7/s Avg:    56 Min:     1 Max:   322 Err:     0 (0.00%) Active: 1 Started: 2 Finished: 1
summary +     15 in 00:00:26 =    0.6/s Avg:    22 Min:     2 Max:    69 Err:     0 (0.00%) Active: 1 Started: 2 Finished: 1
summary =     31 in 00:00:49 =    0.6/s Avg:    39 Min:     1 Max:   322 Err:     0 (0.00%)
summary +     11 in 00:00:31 =    0.3/s Avg:    26 Min:     1 Max:   107 Err:     0 (0.00%) Active: 1 Started: 2 Finished: 1
summary =     42 in 00:01:20 =    0.5/s Avg:    36 Min:     1 Max:   322 Err:     0 (0.00%)
summary +     28 in 00:00:41 =    0.7/s Avg:    17 Min:     0 Max:    71 Err:     0 (0.00%) Active: 0 Started: 3 Finished: 3
summary =     70 in 00:02:01 =    0.6/s Avg:    28 Min:     0 Max:   322 Err:     0 (0.00%)
Tidying up ...    @ Tue Oct 23 19:34:12 PDT 2018 (1540348452863)
... end of run
C:\myDir\

How do I wait for JMeter to finish?

Upvotes: 1

Views: 701

Answers (1)

Ori Marko
Ori Marko

Reputation: 58774

Use CALL instead of START so it won't create new thread.

Also there's option to add to your start command wait option using /W:

/W or /WAIT Start application and wait for it to terminate.

Upvotes: 2

Related Questions