例如,在Python中,我可以执行以下操作:
realout = sys.stdout
sys.stdout = StringIO.StringIO()
some_function() # prints to stdout get captured in the StringIO object
result = sys.stdout.getvalue()
sys.stdout = realout
Run Code Online (Sandbox Code Playgroud)
你能在Go中这样做吗?