2012-02-18 14 views
-1

Javaアプリケーション(実行時)で.batファイルを作成し、.batファイルを実行し、waitFor()メソッドを使用して.batファイルを終了するのを待つ.batファイルを終了します。
プロセスバットファイルの終了待ちなし

コード:

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; 

}


私を助けてください!

+0

答えはここにあるだけ残すために、startを削除します。http://stackoverflow.com/questions/2448402/run-bat-file-in-java-and-wait-2 –

答えて

1

startの使用に関係します。

Process _p = Runtime.getRuntime().exec("cmd /C restore.bat"); 
関連する問題