如何在java中运行此python脚本?
我想在我的java应用程序中使用此脚本: 我环顾四周,试着像这样执行脚本:如何在java中运行此python脚本?,java,python,Java,Python,我想在我的java应用程序中使用此脚本: 我环顾四周,试着像这样执行脚本: public static void main(String[] args) throws IOException { String s = null; Process p = Runtime.getRuntime().exec("python C:\\\\Users\\\\Home\\\\work\\\\test.py"); BufferedReader stdIn
public static void main(String[] args) throws IOException {
String s = null;
Process p = Runtime.getRuntime().exec("python C:\\\\Users\\\\Home\\\\work\\\\test.py");
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
while ((s=stdInput.readLine()) != null) {
System.out.println(s);
}
}
但我没有得到任何输出。我需要什么才能运行此特定脚本?您可以这样使用:
String command = "python /c start python path\to\script\script.py>";
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String line;
while ((line = stdInput.readLine()) != null) {
System.out.println(line);
}
stdInput.close();
while ((line = stdErr.readLine()) != null) {
System.out.println(line);
}
stdErr.close();
p.waitFor();
System.out.println("Done.");
p.destroy();
Protip:始终从“文件资源管理器”选项卡复制路径
既然您得到了JSON响应,请尝试解析它
如果您想使用java大量使用python,请尝试探索我得到了一个
ModuleNotFoundError
。运行该文件所需的所有文件是否应位于同一位置?