首页 > 系统服务 > 详细

linux执行命令直到完成

时间:2015-03-18 17:56:10      阅读:331      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!