如何执行BAT文件?别告诉我Runtime.getRuntime().exec(“x.bat”),它根本不行。 如何执行BAT文件?Runtime.getRuntime().exec()是执行EXE的,BAT不行了``` 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 cmd.exe 环境指明了吗 ,bat是在当前路径吗 ? public static void main(String[] args) {try{Runtime.getRuntime().exec("C:\\aa.bat");}catch (Exception ex){ex.printStackTrace();}}还是不行,太多人认为Runtime.getRuntime().exec()可以执行BAT了,请高手指点一下吧。 Runtime.getRuntime().exec("cmd.exe /c aa.bat");have a try Runtime.getRuntime().exec("cmd.exe /c aa.bat");试了,不行。 要写绝对路径的,如果aa.bat的文件夹不在PATH里面的话。 我前几天刚做过的,100%能行。下面是我实现的类,你用时Command com=new Command("exam.bat")便可以。public class Command{ String cmd; public Command(String cmd) { this.cmd=cmd; try { Process child = Runtime.getRuntime().exec(cmd); InputStream in = child.getInputStream(); int c; while ((c = in.read()) != -1)//这语句不能少,只有读了才能执行 { //System.out.print(c); } in.close(); try { child.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } }} http://blog.csdn.net/gavin_sw/archive/2007/01/22/1489657.aspx public class Test { public static void main(String[] args) { String s = "cmd.exe /c start /min " + "c:\\test.bat"; try { Runtime.getRuntime().exec(s); } catch (IOException e) { e.printStackTrace(); } }} Timer如何制定运行次数和终止执行 怎么让一个人物自己穿过地图 android手机游戏 怎样批处理sql语句,跳过出错语句并纪录日志。 请问JAVA倒3角怎么做....- - Jreator 很不爽的地方,大家一定会碰到的.期待高手 请个熟悉java的人修改一个课程设计(急!)(有酬!) 为什么下载的JDK6.0 双击打不开啊? 郁闷中,请求帮助 最大公约数的问题 JAVA做Server端 请问JDK 1.5.4和1.4.2怎样在同一个电脑中安装? 关于JTAPI的问题,请求高手指点迷津
{try
{
Runtime.getRuntime().exec("C:\\aa.bat");}
catch (Exception ex)
{
ex.printStackTrace();
}
}
还是不行,太多人认为Runtime.getRuntime().exec()可以执行BAT了,请高手指点一下吧。
have a try
试了,不行。
下面是我实现的类,你用时Command com=new Command("exam.bat")便可以。
public class Command
{
String cmd;
public Command(String cmd)
{
this.cmd=cmd;
try
{
Process child = Runtime.getRuntime().exec(cmd);
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1)//这语句不能少,只有读了才能执行
{
//System.out.print(c);
}
in.close();
try
{
child.waitFor();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
String s = "cmd.exe /c start /min " + "c:\\test.bat";
try {
Runtime.getRuntime().exec(s);
} catch (IOException e) {
e.printStackTrace();
}
}}