Runtime run = Runtime.getRuntime(); try { Process p = run.exec(cmd); BufferedInputStream in = new BufferedInputStream(p.getInputStream()); BufferedReader inBr = new BufferedReader(new InputStreamReader(in)); String lineStr; while ((lineStr = inBr.readLine()) != null) System.out.println(lineStr); if (p.waitFor() != 0) { if (p.exitValue() == 1) System.err.println("命令执行失败!"); } inBr.close(); in.close(); |