1

I have textField where i write cmd command and i want to get output results from CMD imported into JtextPane. I am getting that but after i execute some command entire output is imported into the textpane instantly and i want to be written line by line the same way as it being written in CMD console.

thanks for help

String input = textField.getText().toString();
try {
    Process p = Runtime.getRuntime().exec("cmd /c" + " " + input);

    BufferedReader StdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String s;
    while ((s = StdInput.readLine()) != null) {

        try {
            Document doc = textPane.getDocument();
            doc.insertString(doc.getLength(), s + "\n", null);
        } catch (BadLocationException exc) {
            exc.printStackTrace();
        }
    }
} catch (IOException e) {
    e.printStackTrace();
}
Neloop
  • 139
  • 7
markou
  • 11
  • 1
  • Maybe you could try not to use `BufferedReader`, and read char by char directly from the `InputStreamReader` ? – Benoit Sep 09 '19 at 10:28

0 Answers0