我试图从java调用python脚本。 java编译得很好,但没有调用python脚本。
public class javaToPython{
public static void main(String[] args) throws InterruptedException {
try {
Runtime runtime = Runtime.getRuntime();
Process process;
process = runtime.exec("python /home/james/YCSB/bin/pythonycsbcommand.py ");
process.waitFor();
}
catch (IOException ex) {
Logger.getLogger(javaToPython.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
python脚本:
import os
fo = open("/home/james/YCSB/bin/command.txt", "r+")
str = fo.read()
print "", str
fo.close()
os.system(str)
编辑:
我已经尝试过使用流程构建器,但又使用相同的结果。
ProcessBuilder pb = new ProcessBuilder("python", "/home/james/YCSB/bin/script.py", "-m 2");
Process p = pb.start();
我尝试输入一个不存在但java脚本仍在编译的路径。