0

I have a shell script A.sh, it calls a file B.o to run such as the following

#A.sh
B &

So the ampersand states, I am running the process B at the background. However, if B produced an error message, I do not want to see it. I tried to redirect the error message when running A.sh such as

./A 2>&1

but the error messages produced by B still comes up. Is there a way to suppress the error messages that result from a subprocess?

4

1 回答 1

1

这个

2>&1 

将标准错误重定向到标准输出。因此,您将看到 A(和 B)的所有输出。

你可能想要的是:

B 2> /dev/null &

这在后台运行 B 并将标准输出重定向到/dev/null(这是一个接收器,它消失了)。来自 B 的所有正常消息仍然是转发的。但是您可以重定向两个输出流。

B 2> /dev/null > /dev/null &

这会在后台运行 B 并将所有输出重定向到/dev/null.

于 2013-10-26T01:34:08.143 回答