java利⽤Runtime().exec()调⽤python脚本
并传参
//TODO:执⾏python脚本
System.out.println("start python");
//需传⼊的参数
String a = "aaa", b = "bbb", c = "ccc", d = "ddd";
System.out.println("start;;;" + a);
//设置命令⾏传⼊参数
String[] args = new String[] { "python", "C:\\Users\\Desktop\\test1.py", a, b, c, d };
Process pr = Runtime().exec(args);
//TODO:该⽅法只能传递字符串
/
/ Process pr = Runtime().exec("python C:\\Users\\Desktop\\test1.py C:\\Users\\hpp\\Desktop\\test1.mp4");
BufferedReader in = new BufferedReader(new InputStream()));
String line;
while ((line = in.readLine()) != null) {
// line = decodeUnicode(line);
System.out.println(line);
}
in.close();
pr.waitFor();
System.out.println("end");
java调用python模型test1.py (测试是否能取到参数)
import sys
print sys.argv[0]
print sys.argv[1]
print sys.argv[2]
print sys.argv[3]
print sys.argv[4]
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论