Improve broken-pipe detection.

It's silly to keep going with a broken pipe, catching an exception on
each line; just wrap the whole thing in a begin-rescue and stop doing
anything when stdout is closed.
Add text output format.