问题
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