How do I suppress output from this Shell command

自作多情 提交于 2021-02-07 19:16:51

问题


Why are the redirection operations in this command line apparently ignored by bash? I aim to redirect standard error to standard out, and then feed the whole lot into the void.

( cd ../src/ && python -m SimpleHTTPServer 8000 2>&1 > /dev/null ) &

I'm running a SimpleHTTPServer on some static web content, so that wget can check it for dead links. However, I don't want to see the errors from the server (requests for failed pages), as the wget log file provides all the information I need.

Nevertheless, when I run this...

( cd ../log/ && wget --quiet --spider --recursive -o spider.log http://localhost:8000/ 2>&1 > /dev/null )

...the original SimpleHTTPServer command running in the background carries on spewing out Standard Error reports about failed resource requests, like...

127.0.0.1 - - [28/May/2013 17:22:31] "GET /technology/actuator.html HTTP/1.1" 200 -
127.0.0.1 - - [28/May/2013 17:22:31] code 404, message File not found

回答1:


First both stdout(1) and stderr(2) point to your terminal.

You then redirect stderr to whatever your stdout points to. (Which is the terminal.)

Afterwards you redirect stdout to /dev/null. But stderr still points to the terminal.

You can do it the other way around >/dev/null 2>&1: This way you first redirect stdout to /dev/null and then stderr to the same.

Bash provides the shorthand &>/dev/null for this.




回答2:


Use &>/dev/null to suppress everything.



来源:https://stackoverflow.com/questions/16797139/how-do-i-suppress-output-from-this-shell-command

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