I am trying to read an input stream of a process that I create inside an actionPerformed
function of a JButton
for my interface. For that purpose, I have implemented a runnable class. The problem is that I get an output stream in quantas, meaning that, lets say I get 50 lines, than a big pause, and 50 lines more and such. The bigger problem is that the order of lines are not consistent. Here is what my code looks like...
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
{
try{
String sCommand = "cmd /c \"myenvsetup.bat && myprogram.exe\"";
Runtime rt = Runtime.getRuntime();
pr = rt.exec(sCommand);
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
try{
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = null;
while((line = input.readLine()) != null){
jTextArea1.append(line + "\n");
jTextArea1.scrollRectToVisible(new Rectangle(0, jTextArea1.getHeight(), 0, 0));
jTextArea1.update(jTextArea1.getGraphics());
}
pr.waitFor();
} catch (Exception e) {
}
}
});
} catch (Exception e){
}
}