// ********
// Ping the email server to verify it's accessible 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());
2条答案
按热度按时间x0fgdtte1#
Beanshell是JAVA(脚本语言)。下面的语句应该会有所帮助。
tp5buhyn2#
基于@vins的回答,我创建了我的ping测试来验证我的电子邮件服务器是否可用。
另外,如果您想记录
Runtime.getRuntime().exec("COMMAND");
的输出,请在jmeterBeanShell Sampler
中使用类似于以下内容的内容: