nohup:忽略输入并将标准错误重定向到标准输出

ars*_*nal 24 io-redirection nohup stdin stderr

我正在使用nohup如下所述在后台启动我的应用程序-

root@phx5qa01c:/bezook# nohup java -jar ./exhibitor-1.5.1/lib/exhibitor-1.5.1-jar-with-dependencies.jar -c file --fsconfigdir /opt/exhibitor/conf --hostname phx5qa01c.phx.qa.host.com > exhibitor.out &
[1] 30781
root@phx5qa01c:/bezook# nohup: ignoring input and redirecting stderr to stdout
Run Code Online (Sandbox Code Playgroud)

但每次看到这条信息——

nohup: ignoring input and redirecting stderr to stdout
Run Code Online (Sandbox Code Playgroud)

如果我看到这个消息会不会有什么问题?这是什么意思,我该如何避免?

Mar*_*ick 23

为了确保您的应用程序与其终端断开关联 - 以便它不会干扰前台命令并在您注销后继续运行 -nohup确保 stdin、stdout 和 stderr 都不是类似终端​​的设备。该文档描述了它采取的行动:

如果标准输出是终端,则命名实用程序写入其标准输出的所有输出都应附加到当前目录中的文件 nohup.out 的末尾。如果无法创建或打开 nohup.out 进行追加,则将输出追加到 HOME 环境变量指定的目录中的文件 nohup.out 的末尾。如果两个文件都无法创建或打开以进行追加,则不应调用实用程序。

如果标准错误是一个终端,则命名实用程序写入其标准错误的所有输出都应重定向到与标准输出相同的文件描述符。

当您> exhibitor.out在命令行中键入时,您将 stdout 重定向到一个文件。如果您同意将应用程序的 stderr 定向到与其 stdout 相同的文件,则无需执行任何其他操作。或者,您可以通过添加诸如2> exhibitor.err. (感谢一个未知用户 - 我的通知没有显示名称 - 建议包含此替代方案。)

  • 像这样手动关闭输入 fd 也很有用:`</dev/null`; Linux 会自动执行此操作,但如果不手动执行,您仍会在 nohup 的输出中看到一行:`nohup: ignoring input` (3认同)

小智 18

如果将 std 错误重定向到 std 输出,则可以摆脱该消息:

nohup java -jar ./exhibitor-1.5.1/lib/exhibitor-1.5.1-jar-with-dependencies.jar -c file --fsconfigdir /opt/exhibitor/conf --hostname phx5qa01c.phx.qa.host.com > exhibitor.out 2>&1 &
Run Code Online (Sandbox Code Playgroud)


小智 6

在我的情况下,我重定向 stdout 和 stderr,但它也在日志文件中显示以下内容:

nohup: ignoring input
Run Code Online (Sandbox Code Playgroud)

要删除该警告,您还必须按如下方式重定向 stdin:

nohup java -jar ./exhibitor-1.5.1/lib/exhibitor-1.5.1-jar-with-dependencies.jar -c file --fsconfigdir /opt/exhibitor/conf --hostname phx5qa01c.phx.qa.host.com > exhibitor.out 2>&1  </dev/null &
Run Code Online (Sandbox Code Playgroud)

我知道这个答案对你来说肯定晚了,但也许它会帮助其他人。