0

This could is designed to send a request to a server in XML and get a response in XML. It causes the system to freeze

if (!jTextField9.getText().equals("")){
    String reportID = jTextField9.getText();
    try{
    // Report pull code    //"cmd /c omp -u admin -w admin --xml=\"<start_task task_id='" + taskId + "'/>\"";
                     final String dosCommand = "cmd /c omp -u admin -w admin --xml=\"<get_reports report_id='" + reportID + "' format_id='a3810a62-1f62-11e1-9219-406186ea4fc5'/>\"";
                   final String location = "C:\\";
try {
 final Process process = Runtime.getRuntime().exec(
    dosCommand + " " + location);
 final InputStream in = process.getInputStream();
 int ch;
 while((ch = in.read()) != -1) {
    System.out.print((char)ch);

If you need more info please let me know

Thanks

Remotejon
  • 35
  • 9

1 Answers1

2

You should open the external process and read it in another thread, not in the main one. Something like the following:

new Thread(){

  public void run(){
             final Process process = Runtime.getRuntime().exec(dosCommand + " " + location);
             final InputStream in = process.getInputStream();

             int ch;
             while((ch = in.read()) != -1) {
                System.out.print((char)ch);
                /* ... etc */
             }

  }

}.start();

If you don't open a new thread, the main thread (which also draws your graphical components) have to wait the remote response.

robermann
  • 1,722
  • 10
  • 19