bash nohup 和 sed,重定向 stderr 和 stdout
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8426392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
nohup and sed, redirecting stderr and stdout
提问by Steve
On my server nohup sleep 1 > nohup.out &gives no help message. Good.
Running the same command on my laptop, I get: nohup: ignoring input and redirecting stderr to stdout. Although the command still runs and completes correctly, I do not understand why there is a difference in the reporting of this message between my two machines. Fortunately, however, I can resolve this issue on my laptop by simply redirecting stderr and stdout to a file: nohup sleep 1 &> nohup.out &
在我的服务器上nohup sleep 1 > nohup.out &没有任何帮助信息。好的。
在我的笔记本电脑上运行相同的命令,我得到:nohup: ignoring input and redirecting stderr to stdout. 尽管该命令仍然运行并正确完成,但我不明白为什么我的两台机器之间报告此消息的方式有所不同。然而,幸运的是,我可以通过简单地将 stderr 和 stdout 重定向到一个文件来解决我的笔记本电脑上的这个问题:nohup sleep 1 &> nohup.out &
So .... what I'm trying to do is implement a more useful command on my laptop:
所以......我想要做的是在我的笔记本电脑上实现一个更有用的命令:
The following works fine on my server and no message is reported:nohup ls -1 *.txt | sed -e "s%\(.*\)%/home/user/scripts/script.pl -find \1 %" | sh > nohup.out &
以下在我的服务器上运行良好,没有报告任何消息:nohup ls -1 *.txt | sed -e "s%\(.*\)%/home/user/scripts/script.pl -find \1 %" | sh > nohup.out &
This line of code "nohups" a piped list of files into sed, where they are run through script.plconsecutively and executed in shell. script.plprints data to several files, and also prints some info to stdout. I capture this info by writing it to a file called nohup.out
这行代码将文件的管道列表“nohups”到 sed 中,在那里它们script.pl连续运行并在 shell 中执行。script.pl将数据打印到多个文件,并将一些信息打印到标准输出。我通过将其写入名为的文件来捕获此信息nohup.out
Now when I run this one-liner on my laptop, I get nohup: ignoring input and redirecting stderr to stdout. This is expected (but for reasons unknown to me). But when I modify the line to redirect stderr and stdout:nohup ls -1 *.txt | sed -e "s%\(.*\)%/home/user/scripts/script.pl -find \1 %" | sh &> nohup.out &
现在,当我在我的笔记本电脑上运行这个 one-liner 时,我得到nohup: ignoring input and redirecting stderr to stdout. 这是意料之中的(但出于我不知道的原因)。但是当我修改该行以重定向 stderr 和 stdout 时:nohup ls -1 *.txt | sed -e "s%\(.*\)%/home/user/scripts/script.pl -find \1 %" | sh &> nohup.out &
I still get the message nohup: ignoring input and redirecting stderr to stdout
我仍然收到消息 nohup: ignoring input and redirecting stderr to stdout
How can I fix my one-liner so that it runs on my laptop without receiving a message displayed?
如何修复我的 one-liner,使其在我的笔记本电脑上运行而不会收到显示的消息?
回答by potong
I this might work for you:
我这可能对你有用:
nohup ls -1 *.txt 2>/dev/null | .....
The reason being the nohupissues the warning message to stderr, so directing stderrto nowhere 2>/dev/nullditches it.
原因是向nohup发出警告消息stderr,因此指向stderr无处可2>/dev/null抛弃它。

