防止子进程的子进程写入标准输出 [英] Prevent subprocess of subprocess from writing to stdout

查看:55
本文介绍了防止子进程的子进程写入标准输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调用一个子进程并想禁用我的 shell 的任何输出.我正在尝试这样做:

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()

但是仍然有一些输出(但比正常情况少)出现在终端上.问题可能是被调用的进程使用了​​os.execvp?有什么建议可以完全禁用所有子进程的输出吗?

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?

注意

重定向到 devnull 是禁用输出的更好方法:

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()

问题得到解答!

非常简单的解决方案:被调用进程使用CORBA,服务器实际打印出来.

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

推荐答案

如上所述,被调用进程正在调用服务器,该服务器产生了 mysterios stdout.

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

这篇关于防止子进程的子进程写入标准输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆