0

I have some java code that runs a subprocess using ProcessBuilder. I can also capture that process stdout and stderr. The process is an GUI application (not written in Java). So far so good, but sometimes the process fails to open a window yet it keeps running.

How can I detect from Java after e.g. 10 seconds whether the subprocess successfully opened a window? Based on that I would like to take recovery action.

A platform agnostic solution is preferred but not necessary. I can live with solutions specific to Linux, MacOS and Windows.

Queeg
  • 7,748
  • 1
  • 16
  • 42
  • On Windows it can done easily by scanning for pids per HWND with `EnumWindows`. I do this with Foreign Memory API but as that is still changing JDK16+ you might be better off with a script per platform independent of JDK. Some examples to look at: [Powershell](https://superuser.com/questions/1328345/find-all-window-titles-of-application-through-command-line) / [Panama API](https://stackoverflow.com/questions/11067484/get-titles-of-non-java-windows-in-java/75277444#75277444) but you'd need to adapt with call to `GetWindowThreadProcessId` to link up HWND to a your sub-process PID. – DuncG Jul 12 '23 at 12:21
  • Sounds interesting, although I will have to mull over it. – Queeg Jul 12 '23 at 17:01
  • While we are going for external commands/scripts, here is something to help for Linux: https://askubuntu.com/questions/1410275/list-windows-on-command-line – Queeg Jul 12 '23 at 17:01

0 Answers0