I've been browsing SO and google for a while now for an answer to this question, but I can't seem to find one that really works. I'll start from the beginning:
I created a Java class with a method that runs a batch file in the background (the command window does not appear). The program works great, except that it would be a little confusing to the end user, since the batch file takes a while to complete--the user will not know if the program is still running or not. After the batch script finishes executing, a message dialog appears saying it's finished, but for the period of time between when the method is run and the dialog appears, it looks as if the program is doing nothing.
So here's my question: I would very much like to display a new frame with a text area that shows the output of the batch file. However, I understand that this is very difficult to do without creating temporary files, writing to them, reading from them, and so on. I would rather avoid that if possible. Therefore, I have decided it might be better to display an indeterminate JProgressBar while the process is running, and close it when the process is finished. Unfortunately, I don't think Swing can handle this since it would require running multiple processes at once. I have heard of a SwingWorker but am not exactly sure how that would be used in this case. I have the following SSCCE, which works, but does not have the progress bar implemented.
public myClass(){
public static void main(String[] args){
String[] commands = {"cmd.exe", "/C", "C:\\users\\....\\myBat.bat"};
Process p = Runtime.getRuntime().exec(commands);
p.waitFor()
JOptionPane.showMessageDialog(null, "Process finished!");
}
}
While p.waitFor() waits for the process, there is nothing on the screen. I just want something showing the user that a process is still running. Thoughts? Thanks!