0

I need to run a Python script on boot with display support

I have tried using rc.local, cron and a couple of other methods. All of them start the program and it runs as it should but I have a blank screen. I would like to be able to view what the program is doing on the screen. The script uses PyGame and printText to display a status to a small window. It works fine when I run it from a terminal window. I am using Raspbian on a Raspberry Pi 3.

  • I forgot to mention that I am using an ampersand at the end of the line in both the cron and rc.local with still no luck – Ray Dec 29 '17 at 3:38
  • 1
    Hello and welcome, @ray. Please note that you should include all relevant information in the question itself not comments - you can edit to question to do so. – Ghanima Dec 29 '17 at 21:00
  • @Ray Is your program a GUI? – Matt Sep 11 '18 at 4:18
  • try posting your script so that we can see what you're doing. This question is as vague as vague gets. – YetAnotherRandomUser Nov 17 '18 at 18:31
0

I'd output the script to a logfile and, if needed use tail -f on the file to check the output. But if you really want to direct the output directly, note that both cron and rc.local don't have a tty attached. This means that you need to redirect the output of the script to a tty. So in your crontab put something like:

*/10 * * * *  /home/pi/bin/myscript.py &> /dev/tty1

This still won't work (unless when you run the script as root), as the tty by default is owned by root. You can fix this by adding your user (probably pi) to the group tty: sudo usermod -a -G tty pi

Note that you can switch between your terminals with the ctrl-alt-f[1-6] keys (and from a X screen with ctrl+alt+F[1-6])

  • steviethecat, Thanks for your timely reply. My script controls a large dual axis solar tracker so I can tell it is working properly and it also generates log files of what it is doing so I am 100% certain that it is executing properly. I added my user to the tty group and added the line – Ray Dec 29 '17 at 15:05
  • @reboot python /home/pi/Tracker1_6b.py &> /dev/tty1 to the crontab file but it does not execute the script. When I use the line: python /home/pi/bin/Tracker1_6b.py in the rc.local it runs the script but without screen support of course. – Ray Dec 29 '17 at 15:28
  • When I add the line */ * * * * python /home/pi/Tracker1_6b.py to the crontab file it does not run either. I can't say I have ever gotten it to execute from cron. I must have spent 6 hours by now trying to get this to work. – Ray Dec 29 '17 at 15:30
  • In rc.local you can put python /home/pi/Tracker1_6b.py &> /dev/tty1 & – steviethecat Dec 29 '17 at 17:02
  • I tried that and I still have a black screen with the program functioning normally other than the lack of display. I think my setup is pretty generic with a normal HDMI display. – Ray Dec 29 '17 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.