jmeter beashell调用python3脚本并获取python输出值

test3.py代码如下:

 beashell代码如下:

import java.io.BufferedReader;
import java.io.InputStreamReader;
 
String command = "cmd /c python D://个人//test3.py";
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command);
 
pr.waitFor();
 
BufferedReader b = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = "";
StringBuilder response = new StringBuilder();
while ((line = b.readLine()) != null) {
//    log.info(line);
    response.append(line);
 
}
String response_data = response.toString();
log.info(response_data);
b.close();
//System.out.println(response.toString());
vars.put("TEST",response.toString()); //把结果赋值给变量 TEST ,方便后面调用

jmeter控制台输出结果:

 

posted @ 2023-06-27 16:58  Frank13054  阅读(207)  评论(0编辑  收藏  举报