2

I am trying to launch a simple script (let's say it is /home/pi/python/python_code/hello-world.sh) from the /home/pi/.config/lxsession/LXDE-pi/autostart file.

I have added the following line to the autostart file to do this:

@lxterminal -e "/home/pi/python/python_code/hello-world.sh"

The hello-world.sh script runs fine from the command line, but when I boot the Pi, autostart opens a terminal window with hello-world" (note the trailing double quotes) in the title bar and does nothing else.

2
  • Are you sure the two double quotes are the same? Word processors often automatically replace them with left / right quotation marks. You can try leaving them out completely because the script name doesn't contain spaces
    – Dirk
    Feb 15, 2019 at 11:52
  • Thanks for the suggestion. I'm using Idle (in Python 3 environment) as my IDE, and it appears to use basic double quotes (not "sixes and nines" as as common with beginning and ending quotes provided in most word processors). I have also tried replacing the double quotes with single quotes with similar results (i.e., terminal opens on boot showing hello-world' in title bar). Removing the quotes completely gives a different symptom - terminal window appears to open and immediately close upon boot.
    – Ian Simms
    Feb 15, 2019 at 15:39

2 Answers 2

1

Alternatively you could directly add your hello-world.sh to /etc/rc.local

For Example, try this

sudo nano /etc/rc.local

Add your script to end of the file

#!/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.

bash /home/pi/python/python_code/hello-world.sh

To save and exit, type Ctrl-x, and then Y

1
  • Please take note that using /etc/rc.local has limitations due to Compatibility with SysV. We have seen many problems here on this site using it. Following the recommendation of the developers from systemd you should avoid using it.
    – Ingo
    Mar 20, 2019 at 22:51
0

The lxterminal -e "..." is presenting an error when it is started in the autostart file. Example, with the lxterminal -e "Hello World" in the autostart file, the error will display "Hello World" in the title bar. Change that to lxterminal -e "Hello/World" and the error will be World".

Without the quotes around the executable file, it should run fine. However, remember that the executable files in autostart file are forked to run in their own process and when they (lxterminal -e ...) end the process ends also.

If your program is a shell script, add sleep 15 at the end (before the exit command if present) and the terminal will display the information for 15 seconds and then exit. For a Python script add input() to hold the terminal window open.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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