Saving stdout from subprocess.Popen to file line by line

前端 未结 4 1814
滥情空心
滥情空心 2021-02-06 05:42

My python script uses subprocess to call an another script, which produces output very slow(line-by-line basis). I would like to write the output line by line to file not when t

4条回答
  •  被撕碎了的回忆
    2021-02-06 06:10

    I had the same problem for a programming language I'm working on, and ended up doing this: https://github.com/perimosocordiae/plumbum/blob/master/lib/stdlib.py#L21

    Unfortunately, it involves reading from the output stream a character at a time, accumulating the line until a newline is found. It works, though, and I don't know of any other way to get the same behavior.

提交回复
热议问题