nohup 后台运行python程序print无输出
(更新于 )
使用nohup后台运行python,print没有输出到日志 nohup python foobar.py > foobar.log 2>&1 & 发现foobar.log中显示不出来python程序中print的东西。 这是因为python的输出有缓冲,导致foobar.log并不能够马上看到输出。 python 有个-u参数,使得python不启用缓冲。 nohup python -u foobar.py > foobar.log 2>&1 & 其他玩法: 只输出错误到日志 # Only error write to log nohup python -u ./foobar.py> /dev/null 2>foobar.log & 不输出到日志 # Nothing to Display nohup python -u ./foobar.py> /dev/null 2>&1 & 全部print输出到日志 # Write all to log nohup python -u ./foobar.py> ./foobar.log 2>&1 & https://blog.csdn.net/Statham_stone/article/details/78290813