Prevent subprocess of subprocess from writing to stdout

ぐ巨炮叔叔 提交于 2019-12-11 01:01:30

问题


I'm calling a subprocess and want to disable any output to my shell. I'm trying to do this with:

 with tempfile.TemporaryFile() as tempf:
        proc = Popen(cmd, stdout=tempf, stderr=tempf)
        proc.communicate()

But there is still some output (but less than normally) appearing at the terminal. Could the problem be that the called process uses os.execvp? Any suggestions to fully disable the output for all subprocesses?

Note

Redirecting to devnull is a better way of disabling output:

with open(os.devnull, 'w') as tempf:
    proc = Popen(cmd, stdout=tempf, stderr=tempf)
    proc.communicate()

Question answered!

Very simple solution: The called process uses CORBA and the server is actually printing out.


回答1:


As described above, the called process was calling a server, which produced the mysterios stdout.



来源:https://stackoverflow.com/questions/9153796/prevent-subprocess-of-subprocess-from-writing-to-stdout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!