我使用python脚本作为启动程序来启动长时间运行的java服务。无标准输出输出的启动过程
call = [ "java", "-cp", ... ]
with open(os.devnull, 'w') as fnull:
subprocess.Popen(call, stdout=fnull)
print "Service started."
但是当python进程完成后,我仍然从java进程获取stdout输出。我认为这是因为python关闭了我的fnull
,因此它恢复为正常的stdout。
我怎样才能达到我想要的?
编辑:在一个侧面说明,如果可能,仍然会很好,但不会增加任何复杂性。
编辑2:这似乎是我非常愚蠢的,这是正在写的stderr。
你确定它确实是'stdout'而不是'stderr'你看到了吗? – FatalError 2014-08-27 17:04:05
'stdout'指向'/ dev/null',你看不到它。你的java进程可能发送消息到'stderr'。 – 2014-08-27 17:05:07
一旦子进程分叉,父文件描述符会发生什么并不重要。孩子得到/ dev/null。将我的投票加入stderr假设。 – tdelaney 2014-08-27 17:09:33