Page 1 of 1

Autorun Python

Posted: Sun Oct 21, 2012 8:34 am
by davef21370
How can I get a Python program to run on startup?
No keyboard or monitor, just boot the RPi and away it goes.

Re: Autorun Python

Posted: Sun Oct 21, 2012 9:33 am
by eyebee

Re: Autorun Python

Posted: Sun Oct 21, 2012 1:18 pm
by KenT
Just hacked this problem the other day. Answer based on this https://github.com/wireload/screenly-os ... install.sh

Create the folder home/pi/.config/lxsession/LXDE/

/home/pi/.config is already present in the image but you will need to select Show Hidden files in the Filemanager to see it.

In this folder put a file named autostart with one line:

python /home/pi/myprog.py

Re: Autorun Python

Posted: Sun Oct 21, 2012 1:35 pm
by milhouse
Which OS? Presumably Raspbian - in which case adding an init.d script is the preferred solution though if you don't require much control over starting/stopping your script and/or just want a really simple solution, then just add the following to the end of /etc/crontab - it will ensure the script starts at startup (running as user root, which you may or may not want, so consider changing that too):

Code: Select all

@reboot root /path/to/python/script.py

Re: Autorun Python

Posted: Sat Nov 17, 2012 6:44 pm
by beautifulsmall
How do I stop Autorun.
Hope this is relevant to the topic , I have a C programme a.out to send data out of the uart and i autologon and autorun the programme by an added line /root/Desktop/a.out in /etc/local.rc
It runs ok from power on but how can I stop it . The only thing that works is Ctrl-alt-del which reboots !!
running raspbian, I can see text but no prompt.

Re: Autorun Python

Posted: Sat Nov 17, 2012 9:10 pm
by beautifulsmall
rc.local , was the file which runs a.out , the uart sends the data so I know a.out is running but I don't get a prompt and cant get "back in" . any help appreciated.

Re: Autorun Python

Posted: Sat Nov 17, 2012 10:27 pm
by BlackJack
@beautifulsmall: Any chance you did not start the program asynchronously from ``/etc/rc.local`` so that skript never comes to an end and blocks the startup process‽

Can you stop the program by pressing Ctrl + C at the text screen to get to the text prompt?

Re: Autorun Python

Posted: Sun Nov 18, 2012 9:01 pm
by beautifulsmall
The code runs in a continuous loop bursting 8 bytes every second. Ctrl C displays C^ but has no effect. I can use a linux machine tomorrow to edit the file on the SD card so all is not lost and I will add your suggested code. Many thanks.