码迷,mamicode.com
首页 > 系统相关 > 详细

linux执行命令直到完成

时间:2015-03-18 17:57:24      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

以copy命令为例:

public static void run_copy_command(String cpPath, String targetPath) {
  String cpCommand = "cp -rf " + cpPath + " " + targetPath;
  try {
   Process pro = Runtime.getRuntime().exec(cpCommand);
   InputStream stdin = pro.getErrorStream();
   InputStreamReader isr = new InputStreamReader(stdin);
   BufferedReader br = new BufferedReader(isr);
   String line = null;
   System.out.println("<output></output>");
   while ((line = br.readLine()) != null) {
    System.out.println(line);
    System.out.println("");
    int exitVal = pro.waitFor();
    System.out.println("Process exitValue: " + exitVal);
   }
  } catch (IOException e) {
   e.printStackTrace();
  } catch (InterruptedException e) {
   e.printStackTrace();
  }
 }

 

linux执行命令直到完成

标签:

原文地址:http://www.cnblogs.com/lj-insist/p/4347737.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!