[好奇怪]java调用批处理的问题
我需要用java调用一个用java生成的批处理文件(.bat) 代码如下:
Date date = new Date();
String s = "";
try {
File f = new File("c:\\produce\"+date+"\"+date+".bat");
if(!f.exists()){
f.createNewFile();//不存在则创建
BufferedReader input = new BufferedReader(new FileReader(f));
if(input.readLine()==null){
s += "net stop mysql \r\n";
s += "xcopy "c:\\produce\"+date+"\\*.*" "E:\\Program Files\\MySQL\\MySQL Server 5.0\\data\\test\\" /y \r\n";
s += "net start mysql \r\n";
}
System.out.println(s);
input.close();
BufferedWriter output = new BufferedWriter(new FileWriter(f));
output.write(s);
output.close();
}
Runtime.getRuntime().exec("c:\\produce\"+date+"\"+date+".bat");
[解决办法]
哥不会啊,怎么办啊
[解决办法]
把
Runtime.getRuntime().exec("c:\\produce\"+date+"\"+date+".bat");
Runtime.getRuntime().exec("cmd /C "c:\\produce\"+date+"\"+date+".bat"");