Cronjob - How to output stdout, and ignore stderr

烂漫一生 提交于 2019-12-24 13:50:34

问题


Is it possible to output stdout to file, but ignore stderr?

I have a Python script that uses sys.stderr.write(error) to output errors to stderr. I'd like to ignore these for this particular script. How is this possible?

Here is the current entry in the crontab:

* * * * * /Users/me/bin/scrape-headlines /Users/me/proxies.txt >> /Users/me/headlines.txt 2>&1

scrape-headlines is a bash script that calls the Python script.


回答1:


The 2>&1 redirects stderr to stdout, appending it to the headlines.txt. So, redirect stderr to /dev/null:

* * * * * /Users/me/bin/scrape-headlines /Users/me/proxies.txt >> /Users/me/headlines.txt 2> /dev/null



回答2:


You can use the "2" descriptor to control stderr separately and, e.g., redirect it to /dev/null:

* * * * * /Users/me/bin/scrape-headlines /Users/me/proxies.txt >> /Users/me/headlines.txt 2>/dev/null



回答3:


You can redirect stderr and stdout separately.

$ command 1> /some/file 2> /some/other/file

If you want to drop stderr, send it to/dev/null.



来源:https://stackoverflow.com/questions/35522894/cronjob-how-to-output-stdout-and-ignore-stderr

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