public void test(){
String[] cmdarray = null;
//针对cmd命令,参数传递需要以空格为分割,一个空格分割作为一个参数;
cmdarray = new String[] {"cmd.exe ","/c","python","E:\\python\\post.py"};
try {
Process process = Runtime.getRuntime().exec(cmdarray);
BufferedReader in = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line = null;
StringBuffer buffer = new StringBuffer();
while ((line = in.readLine()) != null) {
System.out.println(line);
buffer.append(line);
}
in.close();
int re = process.waitFor();
System.out.println(re);
System.out.println(buffer.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
java调用python实现
最新推荐文章于 2023-03-27 11:16:23 发布