Getting realtime output using subprocess

前端 未结 18 2800
执笔经年
执笔经年 2020-11-22 10:12

I am trying to write a wrapper script for a command line program (svnadmin verify) that will display a nice progress indicator for the operation. This requires me to be abl

18条回答
  •  不知归路
    2020-11-22 11:11

    (This solution has been tested with Python 2.7.15)
    You just need to sys.stdout.flush() after each line read/write:

    while proc.poll() is None:
        line = proc.stdout.readline()
        sys.stdout.write(line)
        # or print(line.strip()), you still need to force the flush.
        sys.stdout.flush()
    

提交回复
热议问题