Windows下执行bat脚本
删除多余文件,新建mytest.bat,内容如下
copy D:tmpmy.txt D:tmpmy_by_bat.txtexit
现文件如图示:
执行代码:
private static void runWinBat() throws IOException, InterruptedException { Process proc = Runtime.getRuntime().exec("cmd.exe /c start D:\tmp\mytest.bat"); int processCode = proc.waitFor(); System.out.println("Process code: " + processCode); }
结果如图示,执行成功
Windows下执行bat脚本
删除多余文件,新建mytest.bat,内容如下
copy D:tmpmy.txt D:tmpmy_by_bat.txtexit
现文件如图示:
执行代码:
private static void runWinBat() throws IOException, InterruptedException { Process proc = Runtime.getRuntime().exec("cmd.exe /c start D:\tmp\mytest.bat"); int processCode = proc.waitFor(); System.out.println("Process code: " + processCode); }
结果如图示,执行成功
举报