String output;
int isSuccessful = 0;
Runtime runtime = Runtime.getRuntime();
Process process = null;
try{
process=runtime.exec("c:/1.bat");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
output=bufferedReader.readLine();
while(output!= null){
System.out.println(output);
output=bufferedReader.readLine();
}
isSuccessful = process.waitFor();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
process.destroy();
System.out.println("process is destroyed;");
}
}
c:/1.bat内容:
dir
输出结果:
D:\workspace\test>dir
驱动器 D 中的卷没有标签。
卷的序列号是 A8B1-7106
D:\workspace\test 的目录
2010-01-08 11:33
.
2010-01-08 11:33 ..
2010-01-11 11:38 279 .classpath
2010-01-08 10:29 380 .project
2010-01-11 11:38 c1
2 个文件 659 字节
3 个目录 38,386,659,328 可用字节
process is destroyed;
阅读(1808) | 评论(0) | 转发(0) |