tags:

views:

48

answers:

1

I am launching a windows process (wrote in C++ but I don't have sources) from Java code in the following way:

 Process p1 = Runtime.getRuntime().exec(cmdAndParams);
 p1.waitFor();

My problem is that the waitFor() method never ends. Thus I tried to launch the process in a simple shell and it ends correctly with many print in the shell (standard output I guess).

Thus I decided to create and start a thread reading the standard output even if I don't need for now these outputs. This fixed the issue.

So my question is the following one: Is this solution the "Java standard to launch and wait for external processes having outputs" or does it means there is an issue somewhere in the native process ? If such an issue exist what C++ programming "error" can be at the origin of the issue ?

+5  A: 

This is an OS thing. The child process is writing to stdout, and that's being buffered waiting for your Java process to read it. When you don't read it, the buffer eventually fills up and the child process blocks writing to stdout waiting for buffer space.

You would have to processes the child process' stdout (and stderr) whichever language you were using.

I suggest you read this article (all 4 pages of it) and implement the recommendations there.

dty
Thanks. The answer was in the Javadoc but at class level and I only read the exec and waitFor methods doc. Next time I'll also read class doc ;-)
Manuel Selva