进程无需等待即可终止 Bat 文件
我在我的java应用程序(运行时)中创建一个.bat文件,然后运行.bat文件并使用waitFor()方法等待终止.bat文件,但不处理等待终止.bat文件。
代码:< br>
public boolean restoreDepot() {
try {
InputStreamReader _input = new
InputStreamReader(getClass().getResourceAsStream("/Depot/DBMakaseb.sql"));
BufferedReader _in = new BufferedReader(_input);
String _currentpath = (new File(".")).getCanonicalPath() + File.separator + "DBDepot.sql";
BufferedWriter _out = new BufferedWriter(new FileWriter(_currentpath));
while (_in.ready()) {
_out.write(_in.readLine());
_out.newLine();
}
_in.close();
_out.close();
String _comCur = "set cur=%cd%";
String _comCD = "Cd /d %PROGRAMFILES%\\MySQL\\MySQL Server 5.5\\bin";
String _comando = "mysql -u root -pm117988m < %cur%" + "\\DBDepot.sql";
String _comExit = "exit";
BufferedWriter _out1 = new BufferedWriter(new FileWriter("restore.bat"));
_out1.write(_comCur);
_out1.newLine();
_out1.write(_comCD);
_out1.newLine();
_out1.write(_comando);
_out1.newLine();
_out1.write(_comExit);
_out1.close();
Process _p = Runtime.getRuntime().exec("cmd /C start restore.bat");
int _res = _p.waitFor();
while (!(((new File(_currentpath)).delete()) && ((new File((new File(".")).getCanonicalPath() + File.separator + "restore.bat")).delete()))) {
}
if (_res != 0) {
return false;
}
return true;
} catch (Exception err) {
System.out.println(err);
}
return false;
}
请帮助我!
I create a .bat file in my java application(Runtime),then run .bat file and use of waitFor() method to waiting for terminate .bat file,but process no wait for terminate .bat file.
Code:
public boolean restoreDepot() {
try {
InputStreamReader _input = new
InputStreamReader(getClass().getResourceAsStream("/Depot/DBMakaseb.sql"));
BufferedReader _in = new BufferedReader(_input);
String _currentpath = (new File(".")).getCanonicalPath() + File.separator + "DBDepot.sql";
BufferedWriter _out = new BufferedWriter(new FileWriter(_currentpath));
while (_in.ready()) {
_out.write(_in.readLine());
_out.newLine();
}
_in.close();
_out.close();
String _comCur = "set cur=%cd%";
String _comCD = "Cd /d %PROGRAMFILES%\\MySQL\\MySQL Server 5.5\\bin";
String _comando = "mysql -u root -pm117988m < %cur%" + "\\DBDepot.sql";
String _comExit = "exit";
BufferedWriter _out1 = new BufferedWriter(new FileWriter("restore.bat"));
_out1.write(_comCur);
_out1.newLine();
_out1.write(_comCD);
_out1.newLine();
_out1.write(_comando);
_out1.newLine();
_out1.write(_comExit);
_out1.close();
Process _p = Runtime.getRuntime().exec("cmd /C start restore.bat");
int _res = _p.waitFor();
while (!(((new File(_currentpath)).delete()) && ((new File((new File(".")).getCanonicalPath() + File.separator + "restore.bat")).delete()))) {
}
if (_res != 0) {
return false;
}
return true;
} catch (Exception err) {
System.out.println(err);
}
return false;
}
Please Help me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这与您对
start
的使用有关。删除
start
,只为离开It has to do with your usage of
start
.Remove
start
, only to leave