In Python, for example, I can do the following:
realout = sys.stdout sys.stdout = StringIO.StringIO() some_function() # prints to stdout get captured in the
I think the whole idea is not advisable (race condition) at all, but I guess one can mess with os.Stdout in a way similar/analogical to your example.