Various ways to start the homebrew program automatically when the Raspberry Pi is turned on

Sometimes we write the corresponding program by ourselves, and it will start automatically when it is turned on. Here are several methods summarized as follows:

1. Programs without interface start automatically when booting

You need to use the vim modifier to modify the /etc/rc.local file, and add the content to be started at the end.

For example, add /home/pi/Desktop/myApp.sh

Then the corresponding sh script will be executed automatically when booting.

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

# 要执行的内容请增加进来
/home/pi/Desktop/myApp.sh

exit 0

2. The program with interface starts automatically

Create a folder under "/home/pi/.config" named "autostart", and create a "myApp.desktop" file under this folder (the file name ends with .desktop, and the previous file name can be customized), the content of the file is as follows:

[Desktop Entry]
Name=mypyapp
Comment=My Python App
Exec=python /home/pi/mypyapp.py
Icon=/home/pi/mypyapp.png
Terminal=false
MultipleArgs=false
Type=Application
Categories=Application;Development;
StartupNotify=true

The above Name (name), Comment (note), Icon (icon) can be customized,

Exec indicates the command to call, which is in the same format as the command input to run the script on the terminal.
After restarting the Raspberry Pi, you can see that your program starts automatically after the Raspberry Pi starts.

Third, there is another method

 In the /etc/xdg/lxsession/LXDE-pi folder, there is an autostart file. At the end of this file, add the program to be executed:

@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver -no-splash
point-rpi

/home/pi/Desktop/myApp.sh

When booting, after the system interface is loaded, the script of /home/pi/Desktop/myApp.sh will be executed.

Guess you like

Origin blog.csdn.net/wangmy1988/article/details/128420800