Java Dealing with child Process
I have a simple script that writes output to the console using ProcessBuilder
. And OutputStreamWriter
see:
Java Process with Input/Output Stream
An earlier thread. I believe my problem rests with the fact a sub process is spawned and the initial Parent process is killed. Resulting in the OutputStreamWriter
to throw a java.io.IOException: Broken pipe exception
. Given the application is spaw开发者_Go百科ning a second process how can I connect my OutputStreamWriter to this new process? Including being able to read back the output it is generating? Is this even possible in Java? Surly java should be able to follow onto the spawned process.
Thanks
Are you calling waitFor() on the process you are running? That should ensure you're parent doesn't complete before the child. You may also want to look at commons exec, which is an open source library designed to make your life easier when running separate processes in Java.
精彩评论