mmkw43
Posts: 768
Joined: Tue Dec 24, 2013 6:18 pm

Autostart script problems

Sat May 08, 2021 8:08 pm

Was working fine now nuthin'

Simply, I can start my script in lxterminal like this --
cd dist
python3.7 myscript.py

(I'm changing the directory to dist as that's the folder pyarmor creates and uses to run).
Anyway, works perfectly with those 2 simple commands.

So --
in the path, /home/pi/.config/autostart/myfile.desktop (chmod755)
[Desktop Entry]
Type=Application
Name=Myfile
Exec=lxterminal -e "cd dist" && "python3.7 myscript.py"
(also tried && "lxterminal -e python3.7 myscript.py")

And I get an open terminal window without a command prompt and nothing.
I've tried everything like /home/pi/dist -- leaving spaces out of the AND sign -- sudo.
A pisser because I had it working but I must be missing something simple.
Like I said at the beginning,
Simply, I can start my script in lxterminal like this --
cd dist
python3.7 myscript.py

and it works fine. -- thanks for any help

SurferTim
Posts: 2054
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Autostart script problems

Sat May 08, 2021 8:36 pm

Code: Select all

Exec=lxterminal -e "cd /home/pi/dist;python3.7 myscript.py"
Semicolon separator worked for me. I don't use the python3.7 thing.
My advice applies to RaspiOS only. Please mention if you use another OS.

User avatar
thagrol
Posts: 4909
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Autostart script problems

Sat May 08, 2021 8:44 pm

Code: Select all

command1 && command2
means run command2 only if command1 succeeds.

The behaviour you describe suggests one of two things:
  1. The "cd" is failing. In which case try with a full path (e.g. cd /home/pi/dist)
  2. The "cd" worked but there is no output from the program you're running. If the program has exited lxterm would likely have closed.
FYI:

Code: Select all

command1 || command2
means run command2 only if command1 fails.

Code: Select all

command1 ; command2
means run command2 after command1.
I'm a volunteer. Take me for granted or abuse my support and I will walk away

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

mmkw43
Posts: 768
Joined: Tue Dec 24, 2013 6:18 pm

Re: Autostart script problems

Sat May 08, 2021 9:20 pm

Ok -- thanks. The semicolon is working.
Funny I tried that first but after reading some bad google *^$% used AND.

Right -- simple AND logic and it flew right by me.
Not the first time.

mmkw43
Posts: 768
Joined: Tue Dec 24, 2013 6:18 pm

Re: Autostart script problems

Sat May 08, 2021 9:30 pm

Btw --
I was wondering if there's any way to keep the terminal window from appearing when you run that autostart? Seems to me I saw an option once, maybe I'm wrong.

And -- is there an easy way to change the default ctl+alt+t to something else?
A file I can edit? --thanks

klricks
Posts: 7771
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Autostart script problems

Sat May 08, 2021 10:54 pm

mmkw43 wrote:
Sat May 08, 2021 9:30 pm
Btw --
I was wondering if there's any way to keep the terminal window from appearing when you run that autostart? Seems to me I saw an option once, maybe I'm wrong.
...
If your script does not interact with the console (keyboard or screen) then no need to use lxterminal.
FYI - Autostart details here: viewtopic.php?f=66&t=294014
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

mmkw43
Posts: 768
Joined: Tue Dec 24, 2013 6:18 pm

Re: Autostart script problems

Sun May 09, 2021 3:20 pm

I wish I would have seen that link before. SO many choices and much to digest.

My program uses tkinter and although I have the desktop file working, I want to make the perfect choice on what to use.

In that link, this is really vague. It says to use "autostart" if you have a GUI application ( which is what I mean by vague) and then goes on to list 4 different methods. I've been able to use the desktop file but could not use the method at /etc/xdg/lxsession/LXDE-pi/autostart (and I wonder why?)

And here's another mystery. When using lxterminal -e it says --
Notes on using lxterminal -e:
(Notes below apply when lxterminal -e is used directly in autostart file. The noted behavior may different than what happens when run from the terminal command line). (confusing) (huh?)

No ‘ or “ in the path/filename to a script. This means that paths or filenames with spaces cannot be used. Use bash script instead.

Only 1 command per line. (Cannot use ; to specify multiple commands). Put multiple commands in bash script instead. (?)


Yet, my desktop file is this (I actually have 2 semicolons) I added a "standby" message which I was pleased to see worked --
lxterminal -e "echo 'STANDBY';cd /home/pi/dist ; python3.7 myscript.py"
Last edited by mmkw43 on Sun May 09, 2021 6:44 pm, edited 1 time in total.

mmkw43
Posts: 768
Joined: Tue Dec 24, 2013 6:18 pm

Re: Autostart script problems

Sun May 09, 2021 4:52 pm

and here --
https://www.makeuseof.com/how-to-run-a- ... t-startup/

at the bottom of the page they use --
/etc/xdg/autostart/file.desktop

which I tried and works fine but not mentioned at all in that link.
?

User avatar
Paeryn
Posts: 3269
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Autostart script problems

Mon May 10, 2021 12:49 am

mmkw43 wrote:
Sun May 09, 2021 3:20 pm
Only 1 command per line. (Cannot use ; to specify multiple commands). Put multiple commands in bash script instead. (?)
[/i]

Yet, my desktop file is this (I actually have 2 semicolons) I added a "standby" message which I was pleased to see worked --
lxterminal -e "echo 'STANDBY';cd /home/pi/dist ; python3.7 myscript.py"
No, you have only one command as far as lxde is concerned and that command is lxterminal, the rest of the line is passed as arguments to lxterminal. What lxterminal does with those arguments is up to it.

<edit: the following only applies to lxde's autostart file and not to any *.desktop files in the autostart directory, on re-reading your post you are using *.desktop files where I think quoted strings do work>

Though I am surprised that lxterminal coped with putting the arguments back into a valid string being that normally the shell would have passed the whole string as one argument (without the outer quotation marks) to lxterminal whereas lxde will have passed it as 6 seperate arguments (including the outer quotation marks as part of the first and last arguments), namely (using one line per argument to show how they are separated)

Code: Select all

"echo
'STANDBY';cd
/home/pi/dist
;
python3.7
myscript.py"
She who travels light — forgot something.
Please note that my name doesn't start with the @ character so can people please stop writing it as if it does!

Return to “Python”