Skip to content

Instantly share code, notes, and snippets.

@jdswinbank
Last active December 20, 2015 13:29
Show Gist options
  • Save jdswinbank/6139455 to your computer and use it in GitHub Desktop.
Save jdswinbank/6139455 to your computer and use it in GitHub Desktop.
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