obspy.core.util.misc.CatchOutput

CatchOutput()[source]

A context manager that catches stdout/stderr/exit() for its scope.

Always use with “with” statement. Does nothing otherwise.

Based on: https://bugs.python.org/msg184312

>>> with CatchOutput() as out:  
...    os.system('echo "mystdout"')
...    os.system('echo "mystderr" >&2')
>>> print(out.stdout)  
mystdout
>>> print(out.stderr)  
mystderr