I'm writing a Java object that runs a Perl script. I use the Process
object to do this. I set everything up, then call the waitFor() method -
and the Java program hangs. I've put debug logging into both the Perl
script and the java program, so I see that the Perl script runs all the
way through, but the last thing the Java program does is execute
waitFor().
The most common bug around this sort of thing is that the parent process
doesn't read all the child's output from its standard output stream. The
buffer for the pipe between the two fills up, and the child then gets
blocked waiting for it to empty so that it can finish writing, which of
course never happens because the parent is waiting for the child to
terminate. Deadlock ensues.
However, from what you say, it sounds like the Perl script is terminating.
Is that definitely the case? Could it be that the script finishes running,
but the buffer is never drained, so the Perl interpreter doesn't exit? Can
you see the interpreter in a process listing after the script seems to
have finished? If you drain all the output from the child, does that help?
If not, i'm not sure what to suggest. I note that the javadoc for Process
does mention that:
The methods that create processes may not work well for special processes
on certain native platforms, such as native windowing processes, daemon
processes, Win16/DOS processes on Microsoft Windows, or shell scripts.
So if a Perl script is like a shell script (and it is - albeit a hideously
deformed shell script with mutant superpowers), there could be trouble.
That sounds more like arse-covering than a genuine warning, though.
tom