I am unable to read the complete output of the program and sometimes it hangs the interface and does not compiles completely. In the output console of the netbeans it displays complete output but not in jtextarea.
Help me out to first execute command in cmd(command prompt) and then read output to textarea from cmd.
In cmd the command executes quickly with complete results. But I have no idea how to get results from cmd.
Here is my code:
String line;
String [] cmds={"xyz.exe","--version"};
try{
Process p =Runtime.getRuntime().exec(cmds);
p.waitFor();
int val=p.exitValue();
if(val==0)
{
b1.setForeground(Color.green);
InputStream ins = p.getInputStream();
InputStreamReader insr = new InputStreamReader(ins);
BufferedReader br = new BufferedReader(insr);
while ((line = br.readLine()) != null) {
System.out.println( line);
t1.setText( line);
}
} else if(val==1)
{
b1.setForeground(Color.red);
InputStream error = p.getErrorStream();
InputStreamReader isrerror = new InputStreamReader(error);
BufferedReader bre = new BufferedReader(isrerror);
while ((line = bre.readLine()) != null) {
t1.setText(line);
}
}
} catch(IOException e){
System.out.println("error");
e.printStackTrace();
} catch (InterruptedException ex) {
Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
}