Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've spent the night trying to figure out how to run a python script in a terminal at startup.

Adding it to init.d will run the script, but I don't see a terminal window or any other indication the script is running other than the audio output the python script produces. I would like to be able to see and interact with this script in a terminal just as if I'd ran it from a terminal.

My next successful step was to make a .desktop file in ~/.config/autostart. My Exec is

Exec=lxterminal -e "python ~/scripts/myscript.py"

When I log in, I see a terminal window flash for just a brief moment - but then disappear. No sound is produced from the python script so I assume it quit running. How do I start a terminal window at system startup and run a Python script in it?

share|improve this question

2 Answers 2

It seems your script is running, but you want the term to stay open. If that's the goal:

Exec=lxterminal -e "python ~/scripts/myscript.py && /bin/bash"  

Should keep the term open for you...

share|improve this answer

I also had experienced some problems with lxterminal as for calling it with the -e argument from inside a .desktop file.

The solution for me was the following:

  1. Make an executable file, named launch_myscript.sh with the content: lxterminal -e python ~/scripts/myscript.py.

  2. Point to this file at your Exec field of the .desktop file that you have placed

Tips: You can try to directly place in your Exec field lxterminal -e python /home/username/scripts/myscript.py. Note that it lacks the " and the ~.

Are you sure that python ~/scripts/myscript.py doesn't produce any error that causes it to exit?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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