【发布时间】:2019-05-30 12:53:08
【问题描述】:
我有一个 .sh 脚本,它通过 nohup 运行大量 Python 脚本。
我使用nohup 在后台运行它们并避免在“nohup: ignoring input and appending output to 'nohup.out'”时按下必要的enter出现消息。
nohup python script2.py 2> /dev/null &
nohup python script2.py 2> /dev/null &
[...]
当我运行这个.sh 时,我得到两个 Python 脚本在后台运行,好的。
此 Python 脚本会生成一个日志文件,我将其导出为 std.stdout:
stream_config = logging.StreamHandler(sys.stdout) <-- here
stream_config.setFormatter(formatter)
importer_logger.addHandler(stream_config)
由于我的实施,我想启动那些nohup,但将标准输出发送到 PID 1
我可以在不使用nohup 的情况下轻松做到这一点,如下所示:
python tester.py > /proc/1/fd/1
但是我该如何结合“不要按回车继续”和“将文件导出到标准输出”?
我尝试了这些但没有运气:
nohup python tester.py > /proc/1/fd/1 2> /dev/null &
nohup python tester.py 2> /proc/1/fd/1 &
提前致谢。
【问题讨论】: