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]

人已赞赏
Java

JDK下载最快地址 3个国内java jdk镜像站【2020最新】

2020-11-16 16:01:08

Java

如何解决docker中启动Spring Boot微服务注册在Eureka后无法访问的问题【附代码】

2020-11-16 17:16:35

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧