Python multiprocessing: How can I RELIABLY redirect stdout from a child process?

前端 未结 5 647
不知归路
不知归路 2020-12-08 14:27

NB. I have seen Log output of multiprocessing.Process - unfortunately, it doesn\'t answer this question.

I am creating a child process (on windows) via multiprocessi

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 14:43

    I don't think you have a better option than redirecting a subprocess to a file as you mentioned in your comment.

    The way consoles stdin/out/err work in windows is each process when it's born has its std handles defined. You can change them with SetStdHandle. When you modify python's sys.stdout you only modify where python prints out stuff, not where other DLL's are printing stuff. Part of the CRT in your DLL is using GetStdHandle to find out where to print out to. If you want, you can do whatever piping you want in windows API in your DLL or in your python script with pywin32. Though I do think it'll be simpler with subprocess.

提交回复
热议问题