public classFirstJavaScript{
public static voidmain(String args[]) {
// Properties props = new Properties();// props.put("python.import.site", "false");// Properties preprops = System.getProperties();// PythonInterpreter.initialize(preprops, props, new String[0]);// PythonInterpreter interpreter = new PythonInterpreter();// interpreter.exec("days=('mod','Tue','Wed','Thu','Fri','Sat','Sun'); ");//interpreter.exec("print days[1];");// interpreter.exec("print('hello')");try{
System.out.println("start");
String[] args1=newString[]{"D:python.py","D:python.py"};
Process pr=Runtime.getRuntime().exec(args1);
BufferedReader in = newBufferedReader(newInputStreamReader(
pr.getInputStream()));
String line;
while((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
pr.waitFor();
System.out.println("end");
} catch(Exception e) {
e.printStackTrace();
}
}
public voidtest(){
System.out.println("我的第一个方法C");
}
}
import numpy as np
if __name__ == '__main__':
a = np.ones(3)
print(a)
print('java 调用有第三方库的python脚本成功')
报错:
start
Disconnected from the target VM, address: '127.0.0.1:51405', transport: 'socket'
java.io.IOException: Cannot run program "D:python.py": CreateProcess error=193, %1 不是有效的 Win32 应用程序。
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at java.lang.Runtime.exec(Runtime.java:485)
at com.wd.emrsearch.python.FirstJavaScript.main(FirstJavaScript.java:27)
Caused by: java.io.IOException: CreateProcess error=193, %1 不是有效的 Win32 应用程序。
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(ProcessImpl.java:386)
at java.lang.ProcessImpl.start(ProcessImpl.java:137)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 3 more
求大神指点