Answer the question
In order to leave comments, you need to log in
How can I run a Python script in the background and write all the data from the console to a separate file?
There is a question! How to run a script in the background, but at the same time make sure that everything that is output to the console is written to a separate file. I'm running Ubuntu 18.04 via SSH server. I'm running a Python bot script for Telegram. I do this with the command: python bot.py & > log.txt and the script runs in the background, but the errors that are written to the console are not written to the log.txt file
Answer the question
In order to leave comments, you need to log in
ampersand to execute in background must be the last character in command
to concatenate stderr and stdout use &>
example
#!/usr/bin/env python3
from __future__ import print_function
import sys
from time import sleep
print('print to stdout')
sleep(2)
print('print to stderr', file = sys.stderr)
python w.py &>w.log &
[1] 4591
[1]+ Done python w.py &> w.log
cat w.log
print to stderr
print to stdout
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question