Home / Java Patterns and Pitfalls     frequal.com

Prevent Child Process from Locking Up by Reading Its Output

Summary

After using Runtime.exec() to create a Process, that process may lock up if its output isn't read in a timely fashion. Symptoms can include: To read its output, get the input stream from Process.getInputStream(). Then read from that stream on a regular basis. If you don't care about the output sent to standard output, make a thread to read the output and discard it. You will need to do the same for the error stream if the processes writes to standard output.

Helper Library

I have written a helper library that does all of this work. It supports several different uses, including those where the output can be discarded and those where the output will be inspected later.

Read more about the Handle Process Output (HPO) library here.


Last modified on 9 Oct 2009 by AO

Copyright © 2020 Andrew Oliver