views:

66

answers:

4

I have a Java process that runs on a Windows server where I have to kick off a command line exe. I am using

Process p = Runtime.getRuntime().exec(command);
OutputStream stdin = p.getOutputStream();
InputStreamstderr = p.getErrorStream();
InputStream stdout = p.getInputStream();

to run the process and capture standard in/out streams. The problem I am having is one of the exe's that I have to run will throw a pop-up message box that needs to have "Ok" clicked on before it will finish failing out.
My Java program is running in the background so it does not have a window for the message box to pop up into, meaning when the exe errors the Java program will hang until someone notices it and kills it in Task Manager.

Is there a way to be able to catch or detect these pop-up boxes from Java?

A: 

No. It's just a process that's running.

Spawning anything that puts up a GUI or any other method of control that cannot be controlled via stdin/out makes little sense.

Cumbayah
Why on earth was that voted down? <sighs> -.-
Cumbayah
I have the same question.
CoolBeans
A: 

No, not directly as far as I can tell. However, you can probably do some form of asynchronous notification. For example you can have the particular app post to a topic in a JSM queue which your app could subscribe to. If you do not have the option of going the JMS route, you can use file notification based triggers. You can have the other app create a dummy file in a common directory and you can have your app monitor that directory.

Bottom line is I do not think you can capture a pop up from another process inside your process. So you will need to do some form of external/asynchronous handling to capture it.

CoolBeans
I will appreciate if you explain the reason behind the down vote? It's not very nice to leave a down vote without a good explanation!
CoolBeans
Undesired truth, I guess. ;/
Cumbayah
+1  A: 

You could be lucky. You could use JNA to call EnumerateWindows or FindWindow of the Win32 API. Then search the button via FindWindowEx.

Then "click" it by calling PostMessage and sending a BM_CLICK

You probably want to have a separate watcher thread that does all this, as your programm waits for the process to end or continue.

Sorry my answer is very rough. Dinner has priority.

allesblinkt
Where that is an approach for sure, I'd think long and hard before starting down that road. For all practical purposes, the application ceases to be a Java application.
Cumbayah
True indeed. But at the same time, the description of the application sounds like it's never going to be used outside a Windows environment.Also when that platform-specific code is tidily encapsulated in a separate class, I would consider it a rather difficult but also clean solution. Where Sunoracle hasn't built the bridges to the underlying OS, you have to do it yourself.
allesblinkt
This is an interesting idea. The application I have is actually a piece of a larger system that needs to run on any kind of OS. This pop-up problem only happens on the Windows servers I have to run on so an idea like this would still work and I could add it in as a layer under the exec() call.
Sean
So it would be a question of `System.getProperty("os.name").toLowerCase().indexOf( "win" ) >= 0` Or you could also write a very little C++ process running alongside your tool, acting as a watchdog and closing that popup. But this is wouldn't be a very clean solution.
allesblinkt
A: 

An inelegant, but simple solution would be to time out.

emory