How can I print and display subprocess stdout and stderr output without distortion?

后端 未结 3 1836
野性不改
野性不改 2020-12-01 13:30

Maybe there\'s someone out in the ether that can help me with this one. (I have seen a number of similar questions to this on SO, but none deal with both standard out and st

3条回答
  •  爱一瞬间的悲伤
    2020-12-01 13:58

    Combining this answer with this, the following code works for me:

    import subprocess, sys
    p = subprocess.Popen(args, stderr=sys.stdout.fileno(), stdout=subprocess.PIPE)
    for line in iter(p.stdout.readline, ""):
     print line,
    

提交回复
热议问题