PowerShell is Buffering Python Stdout

2019-05-12 01:30发布

问题:

I'm running the following command from within a PowerShell script. My problem is that the output from gitstats.py is buffered. This program can take a few minutes and I don't see any of my progress messages until the end.

git log -m -p --word-diff --date=iso | python d:\RepoStats\gitstats.py

within gitstats.py I'm printing using the following syntax:

sys.stdout.write("hi mom")
sys.stdout.buffer.flush()

Any way to get the stdout from python to show realtime in Powershell?