Last active
December 20, 2015 13:29
-
-
Save jdswinbank/6139455 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyrap.measures import measures | |
import os | |
import sys | |
from io import BytesIO | |
from tempfile import SpooledTemporaryFile | |
from contextlib import contextmanager | |
@contextmanager | |
def redirect_stream(stream, destination): | |
old_stream = os.dup(stream.fileno()) | |
with SpooledTemporaryFile() as s: | |
os.dup2(s.fileno(), stream.fileno()) | |
yield | |
s.seek(0) | |
destination.write(s.read()) | |
os.dup2(old_stream, stream.fileno()) | |
output_string = BytesIO() | |
dm = measures() | |
dm.frame_now() | |
with redirect_stream(sys.stderr, output_string): | |
dm.separation(dm.direction("JUPITER"), dm.direction("SUN")) | |
print "Std error of pyrap was: " | |
print output_string.getvalue() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment