阅读背景:

java 利用Runtime.getRuntime().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.getRuntime().exec(args);            //TODO:该方法只能传递字符串//            Process pr = Runtime.getRuntime().exec("python C:\Users\Desktop\test1.py C:\Users\hpp\Desktop\test1.mp4");            BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));            String line;            while ((line = in.readLine()) != null) {//                line = decodeUnicode(line);                System.out.println(line);            }            in.close();            pr.waitFor();            System.out.println("end");//TODO:执行python脚本            System.out.prin



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: