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?
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?