1

Linked to this question: How do I save terminal output to a file?

I understand that I can form an output file by using:

python3 script.py > output.txt

However, I also want to see the output being generated by the python file while it is being saved to output. Is there a simple way to do this on the command line?

Wychh
  • 111

1 Answers1

2

Use a tee command. It is meant exactly for this.

python3 script.py | tee output.txt

It can also be done in more complicated way. Run your original command in the background and simultaneusly view the contents of file output.txt in the foreground. I sometimes prefer to do it that way, especially for long-running processes, since I can at any time abort viewing of the output file and return to it anytime later:

python3 script.py > output.txt &
tail -f output.txt

(you can Ctrl-C in the tail command at any time, and run again the command later).

raj
  • 10,353