Running Command-Line Commands in JMeter Using Groovy
This article demonstrates how to execute operating‑system commands from a Groovy script inside JMeter’s JSR223 PreProcessor, showing the required test plan setup, the Groovy code, and the resulting console output for performance testing purposes.
The previous two posts introduced using Groovy with JMeter for handling assertions and variables; this third article explains how to run command‑line commands from Groovy within a JMeter test.
First, create a simple Thread Group and a basic request, then add a JSR223 PreProcessor (post‑processor would run on the next request). The Groovy script uses the .execute() method to run commands such as jps -lv and jmeter -v , logging the results with log.info and log.error .
Groovy script used:
log.info("jps -lv".execute().text)
"jps -lv".execute().text.eachLine{
log.error("222222222 ${it}")
}
log.info("jmeter -v".execute().text)The console output shows JMeter engine startup messages, thread group execution details, and the logged command output, including error lines prefixed with the custom 222222222 tag.
Although the author is still learning JMeter, the demo is shared to help colleagues who need similar functionality; readers are invited to suggest additional use cases.
Disclaimer: The article was originally published on the "FunTester" public account and may not be reproduced by third parties (except Tencent Cloud).
Technical Article Selections
Linux Performance Monitoring Tool netdata Chinese Translation
Performance Testing Framework, Third Edition
How to Perform Performance Testing Comfortably from the Linux CLI
FunTester
10k followers, 1k articles | completely useless
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.