JMeter执行dos命令

时间:2022-09-02 22:30:43

1.通过java代码实现

参考Java实现操作dos命令

2.直接通过JMeter内置的beanshell脚本操作

String command = "cmd /c start ping www.baidu.com";
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command);

JMeter执行dos命令

 

 

方式2:

Runtime rt = Runtime.getRuntime();  
Process pr
= rt.exec("cmd /c ping www.baidu.com && dir");
//Process pr = rt.exec("D:\\xunlei\\project.aspx");
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream(), "GBK"));
String line
= null;
while ((line = input.readLine()) != null) {
System.
out.println(line);
}
int exitVal = pr.waitFor();
System.
out.println("*******success*******"+exitVal);

JMeter执行dos命令