如何抑制此Shell命令的输出 [英] How do I suppress output from this Shell command

查看:81
本文介绍了如何抑制此Shell命令的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么bash显然忽略了此命令行中的重定向操作?我的目标是将标准错误重定向到标准错误,然后将全部错误输入空白.

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 ) &

我正在一些静态Web内容上运行SimpleHTTPServer,以便wget可以检查它是否存在无效链接.但是,我不想看到服务器中的错误(对失败页面的请求),因为wget日志文件提供了我需要的所有信息.

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 )

...在后台运行的原始SimpleHTTPServer命令继续发出关于失败资源请求的标准错误报告,例如...

...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

推荐答案

首先,stdout(1)和stderr(2)都指向您的终端.

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

然后将stderr重定向到您的stdout指向的任何位置.(哪个是终端.)

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

然后,您将标准输出重定向到/dev/null .但是stderr仍然指向终端.

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

您可以用另一种方法围绕>/dev/null 2>& 1 :通过这种方式,您首先将stdout重定向到/dev/null ,然后stderr相同.

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为此提供了简写&/dev/null .

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

这篇关于如何抑制此Shell命令的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆