Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2044675
  • 博文数量: 519
  • 博客积分: 10070
  • 博客等级: 上将
  • 技术积分: 3985
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-29 14:05
个人简介

只问耕耘

文章分类

全部博文(519)

文章存档

2016年(1)

2013年(5)

2011年(46)

2010年(220)

2009年(51)

2008年(39)

2007年(141)

2006年(16)

我的朋友

分类: Java

2010-01-12 10:36:29

  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;
阅读(1774) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~