String destinationDir = "/home/***/***/***/PDF"; String[] arguments = new String[] {"/home/***/anaconda3/envs/***/bin/python", "/home/***/***/***/pdf2predict.py",destinationDir}; String[] python_str_list = new String[0]; try { System.out.println("python execute running"); Process process = Runtime.getRuntime().exec(arguments); System.out.println("python ok!!!"); BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8)); String line = null; StringBuilder stringBuilder = new StringBuilder(); while ((line = in.readLine()) != null) { stringBuilder.append(line); } in.close(); int re = process.waitFor(); System.out.println(re); System.out.println(stringBuilder.toString()); } catch (Exception e) { e.printStackTrace(); }
Java代码调用python代码时写全路径
最新推荐文章于 2024-07-16 19:26:54 发布