在jmeter中通过beanshell执行shell命令。我想在jmeter
中的beanshell预处理器中执行shell命令任何人都可以告诉你如何这样做。
答案 0 :(得分:6)
Beanshell是JAVA(脚本语言)。 下面的陈述应该有所帮助。
Runtime.getRuntime().exec("COMMAND");
答案 1 :(得分:0)
基于@vins的回答,我创建了ping测试,以验证我的电子邮件服务器是否可用。
此外,如果您想记录Runttime.getRuntime().exec("COMMAND");
的输出,请在您的jmeter BeanShell Sampler
中使用与此类似的内容:
// ********
// Ping the email server to verify it's accessable from the execution server
//
// Preconditions:
// custom variable is available named "emailServer" which contains the IP-Adress of the machine to ping
//
// ********
log.info(Thread.currentThread().getName()+": "+SampleLabel+": Ping email server: " + vars.get("emailServer"));
// Select the ping command depending on your machine type windows or unix machine.
//String command = "ping -n 2 " + vars.get("emailServer"); // for windows
String command = "ping -c2 " + vars.get("emailServer"); // for unix
// Print the generated ping command
log.info(command);
// Create a process object and let this object execute the ping command
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
log.info("Execution complete.");
// Read the output of the ping command and log it
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuilder logCommandOutput = new StringBuilder();
String line;
while( (line = in.readLine()) != null) {
logCommandOutput.append(line);
}
in.close();
log.info("Output: " + logCommandOutput.toString());