import java.io.BufferedReader;
import java.io.InputStreamReader;
public class RunBat {
/**
* 执行批处理
* @param command
*/
public void runBat(String command) {
Process child = null ;
try {
Runtime rt = Runtime.getRuntime();
child = rt.exec(command);
//以下代码为控制台输出相关的批出理
String line = null ;
BufferedReader reader = new BufferedReader(new InputStreamReader(child.getInputStream()));
while ((line = reader.readLine()) != null ) {
System.out.println(line);
}
reader.close();
// 等待刚刚执行的命令的结束
while ( true ) {
if (child.waitFor() == 0 ) break ;
}
} catch (Exception ex) {
child.destroy();
ex.printStackTrace();
}
/**
* @param args
*/
}
public static void main(String[] args) {
RunBat runbat =new RunBat();
runbat.runBat("bat.bat");
}
}