简体   繁体   English

如何禁止此Shell命令的输出

[英]How do I suppress output from this Shell command

Why are the redirection operations in this command line apparently ignored by bash? 为什么这个命令行中的重定向操作显然被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. 我在一些静态Web内容上运行SimpleHTTPServer,以便wget可以检查它是否有死链接。 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. 但是,我不希望看到来自服务器的错误(对失败页面的请求),因为wget日志文件提供了我需要的所有信息。

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... ...在后台运行的原始SimpleHTTPServer命令继续喷出有关失败的资源请求的标准错误报告,如...

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

First both stdout(1) and stderr(2) point to your terminal. 首先,stdout(1)和stderr(2)都指向您的终端。

You then redirect stderr to whatever your stdout points to. 然后,您将stderr重定向到stdout指向的任何内容。 (Which is the terminal.) (这是终端。)

Afterwards you redirect stdout to /dev/null . 然后将stdout重定向到/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. 你可以反过来做>/dev/null 2>&1 :这样你首先将stdout重定向到/dev/null ,然后将stderr重定向到相同的。

Bash provides the shorthand &>/dev/null for this. Bash为此提供了简写&>/dev/null

使用&>/dev/null来压缩所有内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM