Brian McGuinness wrote:Ok. This seems like a rather kludgey approach.
Brian McGuinness wrote:The reason it seems kludgey is that Java has the capabilities necessary to make pipes work, so they should provide a simpler way of creating the pipe connections that I need. For example, providing methods in ProcessBuilder to redirect streams, rather than just files, would solve the problem. It shouldn't be necessary to resort to workarounds.
In any event, I added code to my pipe connector class to close the I/O streams after copying was finished, and now my pipes seem to work properly. Apparently, the output wasn't being flushed, and that kept the threads from terminating. So now I have:
Winston Gutkowski wrote:I think, if I was doing this, I'd actually wrap (or extend) a Process to use 'Piped' versions for its input and/or output streams and then simply chain them myself directly.
And even if I did do what you're doing, I wouldn't try on every iteration, and I certainly wouldn't "swallow" an exception, viz:
Tony Docherty wrote:I agree with the points you make but I'm not sure about closing the streams in the transmit method - if an exception is thrown during the read/write phase the streams will never be closed. I'd suggest moving the stream closure to a finally clause in the run method or use try-with-resources, again in the run method.
Brian McGuinness wrote:Ok. For now I will clean up the pipe connector class as you have suggested.
I will have to experiment with extending the Process class and see what happens.
I find the leading underscores useful for identifying member names since I don't have to search all over the code to find where a variable was defined; I know right away when it's a member, which is defined at the top of the class.