如何在后台将应用程序的输出重定向到/dev/null [英] How to redirect the output of an application in background to /dev/null

查看:358
本文介绍了如何在后台将应用程序的输出重定向到/dev/null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将Linux中的后台应用程序生成的输出重定向到/dev/null.

I would like to redirect the output generated from a background application in Linux to /dev/null.

我正在使用kate文本编辑器,它将在我想重定向到/dev/null的终端上打印所有调试消息.

I am using kate text editor and it prints all the debug messages on the terminal which I would like to redirect to /dev/null.

有什么想法吗?

谢谢

推荐答案

您使用:

yourcommand  > /dev/null 2>&1

如果应在后台运行,请添加&

If it should run in the Background add an &

yourcommand > /dev/null 2>&1 &

>/dev/null 2>&1表示将stdout重定向到/dev/null并将stderr重定向到stdout当时指向的位置

>/dev/null 2>&1 means redirect stdout to /dev/null AND stderr to the place where stdout points at that time

如果您希望stderr出现在控制台上,并且只有stdout进入/dev/null,则可以使用:

If you want stderr to occur on console and only stdout going to /dev/null you can use:

yourcommand 2>&1 > /dev/null

在这种情况下,stderr重定向到stdout(例如您的控制台),然后之后将原始的stdout重定向到/dev/null

In this case stderr is redirected to stdout (e.g. your console) and afterwards the original stdout is redirected to /dev/null

如果程序不应该终止,则可以使用:

If the program should not terminate you can use:

nohup yourcommand &

没有任何参数,所有输出均落入nohup.out

Without any parameter all output lands in nohup.out

这篇关于如何在后台将应用程序的输出重定向到/dev/null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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