I am developing a swing application in which I am running a cmd command using Runtime.getRuntime.execute(); and reading the output of command using BufferReader. Now what I want is I want to show the output in dialog with changing the text(Using JTextPane) inside it or appended strings in a textarea with the output of command like we can see while starting Eclipse of any other IDE for loading prerequisites.
I tried making subclass of JDialog class but it is not doing what i want.
My Code :
Process p = Runtime.getRuntime().exec(commandToBeExecuted);
BufferedReader in = new BufferedReader(newInputStreamReader(p.getInputStream()));
String line = null;
MessageDialog myDialog=new MessageDialog(UserInterface.this);
while ((line = in.readLine()) != null) {
System.out.println(line);
myDialog.setText(line);
myDialog.setVisible(true);
myDialog.setLocationRelativeTo(UserInterface.this);
}
} catch (Exception ex) {
Logger.getLogger(UserInterface.class.getName()).log(Level.SEVERE, null, ex);
errorGlobal.setText("Some Exception Occured in update "+ex.getMessage());
System.out.println("Exception occured " + ex.getMessage());
}
Is it possible to do what I want and what will be the best way to achieve this ?