Frage

I'm trying to run a python script with the nice level set.

nice -n 5 python3 blah.py

runs as expected and sends text output to the screen. However, I would like to pipe the output to a text file and run this all in the background so I can go and check on the progress remotely.

However,

nice -n 5 python3 blah.py > log.txt &

creates the log file log.txt but doesn't write anything to the text file so I'm not sure where the standard output is being sent to or how to direct it to my text file.

War es hilfreich?

Lösung 2

I'm guessing you're running the command via ssh and want to log out between running and checking the log. To do this run:

nohup nice -n 5 python3 blah.py > log.txt &

This will prevent killing the program on logout. As well nohup redirects stderr to stdout, which also might be what's causing an empty log.txt file.

Andere Tipps

I eventually solved this using the command

nice -n 5 python3 -u blah.py >log.txt & 

-u forces the binary I/O layers of stdin, stdout and stderr to be unbuffered. This allows the output of the python script to be written to the text file whilst the process is running.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top