On Fri, Oct 28, 2011 at 09:28:25AM -0700, Sean P. DeNigris wrote:
Thanks David. Is there a way to query whether output/errors are available? I saw some mention of an event driven mechanism, but wasn't clear how to use it.
The event-driven stuff is "under the covers". It basically watches for available data, for example when data is available on the stderr stream of the external process it is automatically pushed into the errorPipelineStream.
The easiest way to see if data is available is to read from the stream and see what you get. For example, if you do #upToEnd and get an empty string, then there is no data available. Note that #upToEnd gives you all of the currently available data (there may be more on the way, for example if the external process is something that runs continuously and puts out data once in a while). If you are dealing with an external program that you expect to run once to completion, then you can use #upToEndOfFile to read everything until the process is complete.
The output and error streams are just streams of data containing whatever happens to come out of the external process. If you are interested in error conditions, you can check exit status of the external process after it runs to completion. Note that the external process may not exit until after you have read its output data (it will block on writing to the pipe if it needs to write a lot of data and you have not read any of it yet), so in general you will want to read the output data, then check exit status afterwards (and maybe read the errorOutputStream also).
Dave