How to print stdout immediately?

后端 未结 2 645
情深已故
情深已故 2021-01-11 09:51

How can I immediately output stdout? stdout is going to print after all input is complete.

require \'open3\'
def run(cmd)
    Open3         


        
2条回答
  •  一个人的身影
    2021-01-11 10:18

    Flush the output

    What you are looking for is to flush the io stream by using the flush method.

    Try the following after each iteration or each puts:

    stdout.flush
    

    If you had multiple puts in a row, I would suggest doing a flush after the last one, so you do not do it too often. Example:

    stdout.puts "Hello"
    stdout.puts "Mate"
    stdout.flush
    

提交回复
热议问题