Java调用bat

>

public class Test { public static void main(String[] args) throws IOException, InterruptedException { String command = “cmd /k D:\ProgramFiles\workspace_eclipse\Java_Maintenanec_System\src\com\dengdie\util\script\rebootwinserver\UpdatePackages.bat”; Process proc = Runtime.getRuntime().exec(command); proc.getOutputStream().close(); StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), “Error”); StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), “Output”); errorGobbler.start(); outputGobbler.start(); proc.waitFor(); } } class StreamGobbler extends Thread { InputStream is; String type; StreamGobbler(InputStream is, String type) { this.is = is; this.type = type; } public void run() { try { InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { if (type.equals(“Error”)) System.out.println(line); else System.out.println(line); } } catch (IOException ioe) { ioe.printStackTrace(); } } }

Java调用bat,布布扣,bubuko.com

Java调用bat

上一篇:(JavaEE-13)国际化开发.md


下一篇:关于C++中的Const常量