首页 > 编程语言 > 详细

Java调用bat

时间:2014-07-22 08:24:05      阅读:373      评论:0      收藏:0      [点我收藏+]
>

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

原文:http://my.oschina.net/u/946001/blog/292718

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!