I have several C / C ++ command line tools that I wrap Java.Swing as a GUI. Command line tools can take minutes to several hours. A progress bar seems like a good idea to keep users sane. I also think that it would be nice to wrap the GUI for a progress bar and not just use the system. But how?
I think command line tools can write percentages in stderr, and I can somehow read them in java. Not exactly what kind of mechanics it is. I also do not understand asynchronous mapping (learned a little about invokeLater ()). New to Java, and would also appreciate general suggestions. Thanks.
--- update ---
Thank you all for your suggestions. Here is the resulting code.
private void redirectSystemStreams() { OutputStream out_stderr = new OutputStream() { @Override public void write(final int b) throws IOException { update(String.valueOf((char) b)); } @Override public void write(byte[] b, int off, int len) throws IOException { update(new String(b, off, len)); } @Override public void write(byte[] b) throws IOException { write(b, 0, b.length); } }; System.setErr(new PrintStream(out_stderr, true)); } private void update(final String inputText) { int value = 20;
source share