In Go, how do I capture stdout of a function into a string?

后端 未结 4 572
庸人自扰
庸人自扰 2020-11-28 06:13

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          


        
4条回答
  •  猫巷女王i
    2020-11-28 06:30

    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.

提交回复
热议问题