2013-03-25 76 views
4

我有很多能产生抑制蟒蛇警告系统范围的cron或者全

/home/intranet/public_html/intranet/bin/utils.py:172: DeprecationWarning: os.popen4 is deprecated. Use the subprocess module. 
    fin, fout = os.popen4(cmd) 

等警告Python脚本的。

有没有办法隐藏他们的系统或整个cron?

谢谢!

回答

4

是否所有其他警告DeprecationWarning s?像这样运行脚本:

python -W ignore::DeprecationWarning thescript.py 

如果你想忽略所有警告,使用

python -W ignore thescript.py 

 

忽略警告系统 - 或者cron的范围内,设置环境变量PYTHONWARNINGS

PYTHONWARNINGS=ignore::DeprecationWarning 
# or PYTHONWARNINGS=ignore 

 

文档:The -W optionPYTHONWARNINGS

 

你用什么Python版本?在2.7中,弃用警告应该被忽略。

+0

我有2.6版本。不幸的是,PYTHONWARNINGS在这个版本中不起作用。 – 2013-03-26 15:23:40

0

如果您希望在通过cron运行程序时不输出,您只需在执行行末尾添加>/dev/null 2>&1即可。 这将重定向您的常规输出为空,但也错误。