今天爱分享给大家带来java 调用python并传参的方法【附代码】,希望能帮助到大家。
public String executePython(String fromPath, String toPath, String picPath, String fileName) {
String success = "500";
String exe = "python";
//要执行python文件的位置
String command = "D:\\pythonProject\\python.py";
//fromPath, toPath, picPath, fileName -->传递给python的参数
String[] cmdArr = new String[]{exe, command, fromPath, toPath, picPath, fileName};
Process process = null;
try {
process = Runtime.getRuntime().exec(cmdArr);
InputStream is = process.getInputStream();
DataInputStream dis = new DataInputStream(is);
//视频处理完成 返回1
String result = dis.readLine();
log.info("python返回结果:" + result);
process.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
return success;
}
python中获取参数
fromPath = argv[1] toPath = argv[2] dirPath = argv[3] txt_path = argv[4]
原文链接:http://blog.itblood.com/1653.html,转载请注明出处。

![NTR 间隙时间做正义的工作 [pc+安卓] [RPG/AI汉化版/动态]](/wp-content/uploads/replace/2025/07/18/39cb8752a9becebbf1505f22f58fe2d9.webp)