java 怎样调用python并传参【附代码】

今天爱分享给大家带来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]
原文链接:https://blog.itblood.com/1653.html,转载请注明出处。
0
业征服v0.1[PC+安卓/1.27G] [日系RPG/AI汉化]
业征服v0.1[PC+安卓/1.27G] [日系RPG/AI汉化]
8分钟前 有人购买 去瞅瞅看

站点公告

显示验证码
没有账号?注册  忘记密码?