Java waiting for the end of a . bat

Asked

Viewed 312 times

0

I have the following scenario:

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

My problem is that I need my Java application to wait for the file to be finished. bat, 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 checks if the file is still open? Because if it is, I can loop until the screen is closed.

  • 1

    Could supplement the question with the code you are using to run the batch file.

  • 1

    Please provide a [mcve] so that it is possible to visualize and test the problem.

  • It is a simple code that generates a file . bat and at the end executes.

  • @Articuno, I said it was simple, look at the answer of #escapistabr...

1 answer

5


I went through something similar and I solved it in the following way:

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

    I think that process.waitFor() should be procBat.waitFor(), right?

  • 2

    Exactly, thank you for the correction!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.