I'm trying to read in from two different input streams (stdin and stderr of a child application) and print them in one combine frame. I've never done this before, and am wondering about best practices.
I can spawn two threads and let them both block on the input stream. Is there a better way?
Thanks!
Your approach is fine, though if you are trying to combine two streams you may get issues with the output/error getting jumbled together.
Perhaps check out Apache commons-exec which is a decent library for handling process invocation and output/error capture. Under the hood it is doing exactly as you suggest, forking threads which read InputStream(s).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With