I have extended RunShellImpl to add some features. In particular, I overrode didProcessFail method, which now scans process standard output and matches it to a user-supplied pattern. I use the parent class’s setOutputStreamObj method to supply my OutputStreamIntf implementation, based on ByteArrayOutputStream, to capture the process standard output. (By the way, why isn’t there a similar way to capture standard error?)
One problem that I ran into is that sometimes when didProcessFail is called, the output stream gobbler has not finished writing to my output stream, and so when I inspect the stream contents, I don’t get the full output. The reason, I think, is that the execute() method of the parent class launches the two stream gobblers and sets them adrift, never joining to the parent thread, so that there is no control over their execution. I think it would be better if the stream gobblers were explicitly joined in the run() method, after the process returns.
Unfortunately, since nearly all methods of RunShellImpl are declared as private, there is only so much I can do in my derived class. Do you have any suggestions for me? For now, I just added a short wait before inspecting the output stream, to give time to the stream gobbler to finish.