最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
java怎么运行getRuntime?java使用Runtime.getRuntime来执行python脚本
时间:2017-02-16 编辑:简简单单 来源:一聚教程网
下面是直接使用Java的一个函数,Runtime类来进行Python脚本的调用。下面对对应的java程序
import java.io.IOException;
public class TestJava {
public static void main(String[] args) throws IOException{
// 使用用Ping命令
//Process ee = Runtime.getRuntime().exec(
//"cmd.exe /c start ping 10.5.2.19");
/*
try{
Runtime rt = Runtime.getRuntime();
//System.out.println("start!");
Process proc = Runtime.getRuntime().exec("cmdpython c:\\Python32\\program\\outfile.py");
proc.waitFor(); //waiting the completion of the command
//System.out.println("end");
}catch (Exception e){
e.printStackTrace();
}
*/
//ok 这个是可以使用的
try{
Runtime rt = Runtime.getRuntime();
System.out.println("start");
Process proc = Runtime.getRuntime().exec("python outfile.py");
proc.waitFor();
System.out.println("end");
} catch (Exception e){
e.printStackTrace();
}
}//main
}
代码如下 | 复制代码 |
上面要求outfile.py是在java工程的根目录下的。
相关文章
- Getting Over It手机版黑屏闪退问题解决 12-08
- 浅谈IOS中AFNetworking网络请求的get和post步骤 04-11
- django model去掉unique_together报错 10-18
- Redis到GET SHELL的例子 08-17
- Redis到GET SHELL的例子 08-17
- python中__getattr__与__getattribute__用法 08-16