JAVA利用Runtime执行多条linux命令
2015-06-08 21:30
302 查看
public static void execPythonShell(File file) throws IOException {
String path = Utils.class.getClassLoader().getResource(“/import.py”)
.getPath();
Runtime runtime = Runtime.getRuntime();
BufferedReader br = null;
try {
String[] cmds = new String[] {
"/bin/sh",
"-c",
"cd " + path + "&&python edit_support_export_infor.py "
+ file.getPath() };
Process process = runtime.exec(cmds);
br = new BufferedReader(new InputStreamReader(
process.getInputStream(), "GBK"));
String tmp = null;
while ((tmp = br.readLine()) != null) {
System.out.println("Shell Message : " + tmp);
}
} catch (IOException e) {
logger.error(e);
} finally {
br.close();
}
}
// -c 意思是执行完成自动关闭,这里多条linux命令通过&&连接到一起
String path = Utils.class.getClassLoader().getResource(“/import.py”)
.getPath();
Runtime runtime = Runtime.getRuntime();
BufferedReader br = null;
try {
String[] cmds = new String[] {
"/bin/sh",
"-c",
"cd " + path + "&&python edit_support_export_infor.py "
+ file.getPath() };
Process process = runtime.exec(cmds);
br = new BufferedReader(new InputStreamReader(
process.getInputStream(), "GBK"));
String tmp = null;
while ((tmp = br.readLine()) != null) {
System.out.println("Shell Message : " + tmp);
}
} catch (IOException e) {
logger.error(e);
} finally {
br.close();
}
}
// -c 意思是执行完成自动关闭,这里多条linux命令通过&&连接到一起
相关文章推荐
- linux下Samba服务器配置攻略
- udev设置
- Linux命令---mpstat命令详解
- linux终端界面的字颜色设置
- JAVA在linux上运行带包的class文件
- Linux命令---Linux vmstat命令实战详解
- 使用BusyBox制作嵌入式Linux根文件系统
- Linux root直接登录
- 群邮件发送
- MFC 连接linux服务器上的mysql数据库
- linux系统常见的压缩命令
- Linux TTY驱动--Uart_driver底层
- 虚拟机下Linux联网配置
- 曾经在linux中用交叉编译工具编了一个可执行文件在android系统的板子上跑,无法执行
- Linux 设备模型之(总线、设备和驱动程序)(三)
- linux:用户和组文件解释(/etc/passwd、/etc/shadow、/etc/group、/etc/gshadow)
- 【Linux 1.0内核源码剖析】执行程序——exec.c
- Linux进程间通信(6.5)
- Linux下批量替换文件内容
- Linux POSIX Message Queue 使用体会