3

I'm trying to integrate with a legacy system. The legacy system uses dialog windows to report errors. It have no return codes at all except for the dialog windows. I start the legacy system with Runtime.exec().

Is there a way to detect if the executed program has spawned dialog windows or any other graphical interface? This solution is done in Windows and the executed program is an exe.

Kevin
  • 53,822
  • 15
  • 101
  • 132
Mikael Svensson
  • 692
  • 1
  • 7
  • 20

3 Answers3

1

If the legacy system report errors in console, is possible get your erros.
Simply take the inputstream of error and do your reading.

Like this:

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd);
// any error message?
InputStream error = proc.getErrorStream(); 
InputStreamReader isr = new InputStreamReader(error);
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
      System.out.println(" ERROR >" + line); 

I recommend to read: Runtime.exec() quirks

Hope this help.

Anderson Carniel
  • 1,711
  • 2
  • 16
  • 22
1

You can use this JNA snippet to poll for windows started by your process.

AFAIK, you can only get the standard and error output streams from a process using the Java Process API.

Community
  • 1
  • 1
Garrett Hall
  • 29,524
  • 10
  • 61
  • 76
0

So the solution i did, is to use the snippet code that @Gerrett Hall linked to. That snippet code check the active window before i run the command and save the name.

Then after a vile if the command have not returned check if the active window have changed. if it have, kill the process(Alt. send a return key global).

To get the info from the dialog i could use Ctrl + C to copy the content of the dialog and reading the paste buffer to copy the message in to the log. Have not figured out that part yet.

And yes this is a ugly hack but so is the legacy system to.

Mikael Svensson
  • 692
  • 1
  • 7
  • 20