Redirect script output to /dev/tty1 and also capture output to file
Solution 1
Thanks for the input, it did not work for Python scripts because it was buffering the output.
This allows it to work with tee:
python -u ./myscript.py | tee /dev/tty1 /tmp/a.txt
Solution 2
If you want to save the output of a command, use the script command
script -c "your command" /tmp/capture.txt
The output will be sent to the tty and also to capture.txt
If tty1 is not the console that you are running from, you could run a
tail -F /tmp/capture.txt
from that tty in order to get the results there as well.
Related videos on Youtube
PhilBot
Updated on September 18, 2022Comments
-
PhilBot over 1 year
I want to display text output on the console that is always displayed on a small screen on my Raspberry Pi.
The following code works for showing that text output:
cd /home/pi/python_test_scripts_linux && sudo nice -n -20 /home/pi/python_test_scripts_linux/test_wrapper.py > /dev/tty1
Now I want to capture the output in parallel with seeing it on the screen - I have tried 'tee' but that does not show text on the screen and also does not capture it to file:
cd /home/pi/python_test_scripts_linux && sudo nice -n -20 /home/pi/python_test_scripts_linux/test_wrapper.py | tee /dev/tty1 /tmp/capture.txt
How can I redirect the output of my script to
/dev/tty1
so I can see it on my screen but also capture the output to file?UPDATE 1:
Per the answer below - I tried using 'script' - unfortunately it did not work:
script -c "cd /home/pi/python_test_scripts_linux && sudo nice -n -20 /home/pi/python_test_scripts_linux/test_wrapper.py > /dev/tty1" /home/pi/python_test_scripts_linux/report.html
UPDATE 2:
I also tried to 'tail' the output of the file that I redirected the output to into /dev/tty1, but it also did not work:
sudo tail -F /home/pi/python_test_scripts_linux/report.html > /dev/tty1 & cd /home/pi/python_test_scripts_linux && sudo nice -n -20 /home/pi/python_test_scripts_linux/test_wrapper.py > /home/pi/python_test_scripts_linux/report.html
-
PhilBot about 9 yearsHi Robert - thanks for the input. I tried launching this over an SSH terminal: script -c "cd /home/pi/python_test_scripts_linux && sudo nice -n -20 /home/pi/python_test_scripts_linux/test_wrapper.py > /dev/tty1" /home/pi/python_test_scripts_linux/report.html
-
PhilBot about 9 yearsHowever, the text that is redirected to /dev/tty1 does not get captured in the /tmp/capture.txt file. Only errors if I kill the process. Any other ideas?
-
mahendra yadav about 9 yearsDon't redirect to /dev/tty, redirect to /tmp/capture. Then try tail -F /tmp/capture > /dev/tty1 & . Start the tail first in background. and kill when done.
-
PhilBot about 9 yearsthanks for the suggestion but it had the same effect. /dev/tty1 must be special?
-
mahendra yadav about 9 yearsCheck to see if you have permission to write to the tty. "ls -l /dev/tty1". Fix permission if required.
-
mahendra yadav about 9 yearsTry : script -c "script -c 'your command /dev/tty1' /tmp/capture "