Java wait for the end of the execution of a .bat

0

I have the following scenario:

  • I have a Java application with Swing;
  • Where by means of a jTextField, I get some information;
  • With this information, I create a .bat
  • This .bat calls an .exe file with the parameters obtained by jTextField.

My problem is that I need my Java application to wait for the .bat file to finish, because to continue the process in the Java application without errors, I need the information that this .bat will return.

Is there a function that verifies that the file is still open? Well if you have, I can loop until the screen is closed.

    
asked by anonymous 16.02.2018 / 14:03

1 answer

5

I went through something similar and solved it as follows:

Process procBat = Runtime.getRuntime().exec([comando]);
int retorno = procBat.waitFor(); // Se o retorno for 0 então o processo executou com sucesso
    
16.02.2018 / 14:11