以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(); } }
时间: 2024-10-19 15:52:02