I have a Java application that takes data from stdinand writes the results to stdout. Like this:
app1 | java_app | app2
The amount of data moving through the pipe is large and takes a lot of time (hours and days are not something unusual or unexpected).
It seems that if he app1dies and closes his pipe end, I get an exception related to the pipe. However, he app2dies and closes his end of the channel. I do not get an exception. This means that it java_appcontinues to consume input, which will never generate a useful output, working for several hours or days.
The difference in the pipe exception messages appears to be related to System.inhow InputStream, and System.out- PrintStreamand PrintStream. I know that you can get the error state from PrintStreamwith stream.checkError()- but using this everywhere is inconvenient (and forces the stream of your output stream). I am happy to abandon the core functionality PrintStreamin order to improve error reporting.
Is there any other way to access stdout that is not wrapped in PrintStream, but is better instead OutputStream?
source
share