【问题标题】:Run nohup with multiple command-line arguments and redirect stdin使用多个命令行参数运行 nohup 并重定向标准输入
【发布时间】:2013-10-09 23:48:22
【问题描述】:

我想跑步

python argument1.txt argument2.txt >logfile.log

使用 nohup,但我没有得到输出,因为它将输入重定向到 null。 我希望它首先接受命令行参数并以 nohup 方式工作。

nohup python argument1.txt argument2.txt >logfile.log

当我运行上述命令时,我得到以下输出。 nohup:忽略输入并附加... 这意味着参数被忽略。手册上说我必须做一些输入重定向,我不知道该怎么做。

【问题讨论】:

  • 您在标题中提到了重定向标准输入,但在问题中没有进一步提及。问题是什么?您应该能够运行:nohup python argument1.txt argument2.txt <input.file > logfile.log 2>&1 并且不应该有来自 nohup 的任何噪音(并且没有 nohup.out 文件)并且标准输入应该来自命名文件并且标准输出和标准错误都应该转到日志文件。

标签: python linux daemon nohup


【解决方案1】:

nohup 重定向到 nohup.out

如果您希望获得 nohup 外观并重定向到另一个文件,请执行以下操作:

( python argument1.txt argument2.txt >logfile.log 2>logfile.err & ) &

当您注销时,这不会挂断。 (您可以通过将2>logfile.err 替换为2>&1 来将stderr 重定向到相同的日志文件

【讨论】:

  • (1) nohup 在 stdout 和 stderr 都没有到达终端时不会重定向到 nohup.out。 (2) nohup 确实安排在运行程序之前忽略 HUP 信号。要修复 (2),您需要在 python 命令之前添加 trap '' HUP;。但根本没有必要这样做。而且您还没有涵盖标准输入,问题标题提到但正文没有。
  • 当我运行上述命令时,我得到以下输出。 nohup: 忽略输入和附加 ... 这意味着 areguments 被忽略。手册上说我必须做一些输入重定向,我不知道该怎么做。
猜你喜欢
  • 2022-01-26
  • 2011-11-28
  • 1970-01-01
  • 2013-07-05
  • 2010-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-12
相关资源
最近更新 更多