如何在后台将应用程序的输出重定向到/dev/null

编程入门 行业动态 更新时间:2024-10-23 18:35:11
本文介绍了如何在后台将应用程序的输出重定向到/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

本文发布于:2023-07-06 07:33:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047338.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   重定向   后台   如何在   null

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!