码迷,mamicode.com
首页 > 编程语言 > 详细

Java调用bat

时间:2014-07-22 08:28:35      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:java   os   io   art   for   re   

>

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

标签:java   os   io   art   for   re   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!