原文 http://blog.youkuaiyun.com/gavin_sw/archive/2007/01/22/1489657.aspx
try{
String exeBat = "c:\test.bat";
Process child = Runtime.getRuntime().exec(exeBat);
InputStream in = child.getInputStream();
BufferedReader br= new BufferedReader(new InputStreamReader(in));
String line = br.readLine().toString();
while(line!=null ){
System.out.println(line); //输出测试
line = br.readLine().toString();
}
try{
child.waitFor();
br.close();
in.close();
}catch (Exception e) {
e.printStackTrace();
}
}catch (Exception e) {
e.printStackTrace();
}
本文提供了一个Java代码示例,展示了如何通过Java程序来调用并执行Windows批处理文件(.bat),同时捕获并输出批处理文件执行过程中的输出信息。
3352

被折叠的 条评论
为什么被折叠?



