Refactoring to support a Popen-like interface.