I have a program that I want to run when the Pi starts up; it is the only program I expect to run in this environment; when the program ends, the Pi can shut down (after I'm done debugging things).
Doing internet searches for this, I find lots of posts detailing various ways to do this, but little detail about the differences among them, and sometimes little enough about the environment needed to use them. The program I'm going to run is a Python script, using wxPython for a UI that will occupy the entire screen. Ideally, no other splash screen or anything would appear before the program's UI; the user would turn on the machine, there would be some blinking lights (no other splash screen), and the program's UI would be the next thing he or she would see.
I've seen references to LXDE and plymouth; I am new to the Raspberry Pi environment and don't know whether I'm using them or not. I started with an image file from a company that makes the 5-inch display I have. I'd be happy to know how to figure out whether I'm using those.
I set the Pi to autologin to the desktop from boot, and created an X.desktop file in ~/.config/autostart. It originally contained:
[Desktop Entry]
Type=Application
Name=X App
NoDisplay=false
Exec=xterm -hold -e python3.7 /home/pi/X/X.py
This works, but it invokes the program from some default directory not under my control. I would like to know if there's a way to set the default directory; this is partially so that the logging setup I have will work (it opens a file in the default directory, and if I figure out a directory when the code starts running, it cannot contain messages from before that.
I tried making the Exec command cd <directory> ; python3.7 X.py
, but the second command gets executed after the first one, but doesn't get the benefit of the effect of it. I tried putting the cd
and the python3.7
commands into a .sh file and executing that with source Exec=/home/pi/X/X.sh
, but I get an error that there is no such directory.
Is there a good way to do this?
I should also say that I'm only using xterm so that I can debug things arising from the python command -- I'm aware I could just invoke python from the file, and when I'm more confident it's working I will do that.