java 程序调用执行Dos命令和bat文件

时间:2022-09-30 09:33:41
public void run(String batName) {
try {
Process ps = Runtime.getRuntime().exec("cmd.exe /c start " +batName); //这样会导致,dos窗口不消失 <pre name="code" class="java"> Process ps = Runtime.getRuntime().exec(batName); //这样,解决上面的问题
ps.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
Test t = new Test();
String batName = "C:\\Users\\Administrator\\Desktop\\1.bat";
t.run(batName);
}