I have a Java-Gnome GUI which starts a separate thread to run a command line program that I do not have the code to. I would like to display a progress bar in the GUI to show what percentage of the second thread has been completed so far.
Given that I/my program does not control the external program is this possible or am I stuck with an indeterminate pulsing progress bar? Thanks
When the command line program reports its progress in the console, you can read this output in your java application. In order to do that, you have to create a Process object using a ProcessBuilder:
Now you can read the
outputStreamobject to get the text output of the command line program.This will of course only help you when the command line program reports its progress to stdout and when this output can be used to determine how much work is left. When the program doesn’t expose this information, there is no way to find out its progress (in fact, according to the halting problem, it’s impossible to tell how long a program will run without executing it completely).