进程无需等待即可终止 Bat 文件

发布于 2025-01-07 02:30:52 字数 1613 浏览 1 评论 0原文

我在我的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赏烟花じ飞满天 2025-01-14 02:30:52

这与您对 start 的使用有关。

删除start,只为离开

Process _p = Runtime.getRuntime().exec("cmd /C restore.bat");

It has to do with your usage of start.

Remove start, only to leave

Process _p = Runtime.getRuntime().exec("cmd /C restore.bat");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文