linux执行命令直到完成

以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();
  }
 }

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。