New context manager to catch the output.

This variant does not leak file descriptors.
Nested with does not work with Python 2.6.
Merge pull request #698 from obspy/catchoutput_cm

New context manager to catch the output.