Capture stdout from a script in Python,sys.stdout.write('foobar')