Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting Graphical interface after calling Runtime.exec()

Tags:

java

runtime

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.

like image 470
Mikael Svensson Avatar asked Nov 26 '25 15:11

Mikael Svensson


2 Answers

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.

like image 137
Anderson Carniel Avatar answered Nov 29 '25 03:11

Anderson Carniel


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.

like image 27
Garrett Hall Avatar answered Nov 29 '25 05:11

Garrett Hall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!