Runtime.exec() and a repaint problem with JEditorPane

S

Steve Sobol

So I have this call to Runtime.exec():

public static void CmdExec(String cmdline, CmdExecCallback cb)
throws Exception {
String line;
Process p = Runtime.getRuntime().exec(cmdline);
BufferedReader input =new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
cb.doCallback(line);
}
input.close();
}

cb is a callback function that implements this interface:

public interface CmdExecCallback {
public abstract void doCallback(String s);
}

This code calls the CmdExec function. The callback function updates a
JEditorPane:

try {
UndiesUtils.CmdExec("ping " + pingArg, new CmdExecCallback() {
public void doCallback(String s) {
appendOutput(s);
}
});
} catch(Exception e) {
System.out.println("CmdExec exception: " + e.getStackTrace());
}
System.out.println("Done");

and appendOutput consists of

private void appendOutput(String s) {
getEpOutput().setText(getEpOutput().getText() + s + "\r");
System.out.println(s);
this.repaint();
}

In appendOutput() the call to println is just for debugging. What I really
want to do is populate the JEditorPane with the output of the ping command.
And that works. But I have to wait until the process exits to see the output
in the JEditorPane, even though I call repaint().

How do I display each line in the JEditorPane as it comes in?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top