Python Run a daemon sub-process & read stdout

后端 未结 3 659
暗喜
暗喜 2020-11-29 04:52

I need to run a program and gather its output to stdout. This program (socat) needs to run in the background for the duration of the python script. Socat sits in dameon mode

3条回答
  •  天命终不由人
    2020-11-29 05:32

    The subprocess probably never closes stdout, so the read() call waits forever. To make matters worse, it will probably buffer its output when it figures out that it's a pipe instead of a console (the standard C library does this automatically, so this isn't a function of how cleverly written the app is). If so, probably the only option is to use an expect-style library such as Pexpect.

提交回复
热议问题