Nohup is not writing log to output file

user1642513 picture user1642513 · Oct 16, 2012 · Viewed 76.6k times · Source

I am using the following command to run a python script in the background:

nohup ./cmd.py > cmd.log &

But it appears that nohup is not writing anything to the log file. cmd.log is created but is always empty. In the python script, I am using sys.stdout.write instead of print to print to standard output. Am I doing anything wrong?

Answer

vz0 picture vz0 · Oct 16, 2012

You can run Python with the -u flag to avoid output buffering:

nohup python -u ./cmd.py > cmd.log &