python 脚本如何在后代运行并记录标准输出


nohup python main.py &

nohup python main.py 2>&1 &

nohup python main.py > main.out 2>&1 &

上面三种方式无论在nohup.out 或main.out都看不到数据结果,这是因为python执行有缓存输出。

解决:使用-u参数

nohup python -u main.py > main.out 2>&1 &