0

I'm launching an E4 Application installed as someProgram.exe from within another E4 Application using

Runtime.getRuntime().exec("someProgram.exe_path");

This does in fact launch the someProgram.exe but when a user starts any interaction in the someProgram.exe application, it becomes unresponsive, hangs and / or freezes. I've tried this with ProcessBuilder and "Runtime exec", in both cases someProgram.exe hangs.

I've tried the call of Runtime.getRuntime().exec("someProgram.exe_path"); from a simple Java class with a Static Main function and someProgram.exe launches and works perfectly as expected no hanging and normal response times.

Alternatively, we've used

Desktop.getDesktop().open(someProgram.exe_file);

which launches someProgram.exe perfectly without issue also, however we would like to send an argument with the launch request of someProgram.exe and Desktop unfortunately cannot provide that functionality.

Moreover, when using the "Runtime exec" method which hangs, if I quit the program calling "Runtime exec" on someProgram.exe, then someProgram.exe begins to work just fine and all hanging stops.

Also, If I put the "Runtime exec" call in a process, launch using "Runtime exec" sleep the thread, and later destroy that process then someProgram.exe quits.

Wondering if either E4 RCP application (or someProgram.exe) has something that happens in the "launch" of the application or the application life cycle of someProgram.exe which is not letting go when another program calls "Runtime exec" on it? Or if the calling application needs to call Runtime in another manner to allow it to essentially release control since control with this process doesn't seem to get returned to the launching program for it to complete its process.

Or possibly if there is another means of achieving this launch of somePrograme.exe with Args that would work without hanging.

Like I said, someProgram.exe hangs only when launched from another RCP App using a process, ProcessBuilder or "Runtime exec". A Java class calling "Runtime exec" works fine. Desktop.open() works fine as well.

Thanks in advance for your suggestions.

  • Marv
Marv
  • 77
  • 9

1 Answers1

0

The solution to this was using inheritIO() method on ProcessBuilder:

ProcessBuilder pb = new ProcessBuilder(commands).inheritIO();

Equally effective would be to use:

pb.redirectInput(Redirect.INHERIT);
pb.redirectOutput(Redirect.INHERIT);
  • Hope this helps others in the future.

From Java Docs:

inheritIO
public ProcessBuilder inheritIO()
Sets the source and destination for subprocess standard I/O to be the same as those of the current Java process. 
This is a convenience method. An invocation of the form 

 pb.inheritIO()

behaves in exactly the same way as the invocation 

 pb.redirectInput(Redirect.INHERIT)
   .redirectOutput(Redirect.INHERIT)
   .redirectError(Redirect.INHERIT)

This gives behavior equivalent to most operating system command interpreters, or the standard C library function system().
Returns: 
this process builder 
Since: 
1.7
Marv
  • 77
  • 9