Prevent subprocess of subprocess from writing to s

2019-07-20 21:50发布

问题:

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.