Fixed a bug where the resulting data would be blank.

Changed the exit event to be 'close' since 'exit' can be sent even though the stdio streams are still open. The alternative is to use the 'close' event which is emitted when all stdio streams are closed and the program has exited.