Skip to content

Instantly share code, notes, and snippets.

@xebecnan
Last active December 27, 2015 20:49
Show Gist options
  • Save xebecnan/7387742 to your computer and use it in GitHub Desktop.
Save xebecnan/7387742 to your computer and use it in GitHub Desktop.
Windows下正确显示程序打印的UTF8中文
import sys
from subprocess import PIPE, Popen, STDOUT
args = sys.argv[1:]
process = Popen(args, stdout=PIPE, shell=True, stderr=STDOUT)
count = 0
while True:
buff = process.stdout.readline()
if buff == '':
count += 1
if buff == '' and process.poll() != None:
break
sys.stdout.write(buff.decode('utf8'))
process.wait()
sys.exit(process.returncode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment