pythonで標準出力を拾う

Pythonだとこんな感じだお from StringIO import StringIO buffer = StringIO() sys.stdout = buffer exec code # なにかprintするような処理をするcode sys.stdout = sys.__stdout__ print buffer.getvalue() # ここで拾った出力を表示