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

Wrapper script?

Thu May 06, 2021 7:54 pm

I remember having to write a simple script that would start another and that's the only way I could get the program to run using autostart. The main program uses python and tkinter.

So if I --
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
and --
put @/usr/bin/python3.7 start.py

and --
start.py simply had the command --
subprocess.call python3.7 mymain.py

it would work fine.
now, it seems I'm having the same problem with another project and just read in a post somewhere, someone referred to a "wrapper" script that talked about the same thing. Starting a script with another.

Why does this work (in my case anyway) and WHY is it needed?

-- thanks

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

Re: Wrapper script?

Thu May 06, 2021 8:56 pm

I use python3 and pygame, but same principle.
Check if directory "/home/pi/.config/autostart" exists. If not create it.
Create new .desktop file:

Code: Select all

nano /home/pi/.config/autostart/myscript.desktop
Add this to myscript.desktop

Code: Select all

[Desktop Entry]
Type=Application
Name=Myscript
Exec=lxterminal -e '/usr/bin/python3 /home/pi/python/myscript.py
Make it executable

Code: Select all

chmod 755 /home/pi/.config/autostart/myscript.desktop
Reboot
My advice applies to RaspiOS only. Please mention if you use another OS.

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

Re: Wrapper script?

Thu May 06, 2021 9:03 pm

Ok Tim. Thanks. I've seen this before but honestly never tried it. I'm guessing it's fine with a gui script using tkinter? I always was drawn to that autostart as I've seen it's the way to do it with a gui program.

I'll try it.

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

Re: Wrapper script?

Thu May 06, 2021 9:05 pm

It should work fine. It runs as user 'pi'.
Like I said, I use pygame, and it is a GUI.

Edit: This assumes the RPi boots into the desktop, not CLI.
My advice applies to RaspiOS only. Please mention if you use another OS.

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

Re: Wrapper script?

Thu May 06, 2021 9:15 pm

just to clarify this line --

Exec=lxterminal -e '/usr/bin/python3 /home/pi/python/myscript.py

in my case,
"/usr/bin/python3.7 (1 space)/home/pi/dist/python*/myscript.py"

I used pyarmor to obfuscate so it's all in the dist folder but in the path you just use "python" ? (*)

thanks

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

Re: Wrapper script?

Thu May 06, 2021 9:50 pm

Yes. Booting to the desktop.
Created the desktop file but no luck so far but it may have something to do with the py file location?

I used pyarmor and it creates a dist folder with the obfuscated python script.

I'll keep trying.

Also, when I just use nano and not sudo nano, I get a warning that the file isn't writeable and permission is denied.

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

Re: Wrapper script?

Thu May 06, 2021 10:19 pm

Did you create the file using sudo? You shouldn't. That should use root as the user and group.

Edit: You want the file's owner and group as 'pi'.
Last edited by SurferTim on Thu May 06, 2021 10:20 pm, edited 1 time in total.
My advice applies to RaspiOS only. Please mention if you use another OS.

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

Re: Wrapper script?

Thu May 06, 2021 10:20 pm

ok -- will redo it and see.
tnx.

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

Re: Wrapper script?

Thu May 06, 2021 10:56 pm

Tim --

How can I change the directory first in the command?
I need to change it to /home/pi/dist and then execute the py script

I mean I know I can simply do a cd but unsure how I do it in the autostart file once I open lxterminal. Can you just do a couple strings separated with a comma or something?

Exec=lxterminal > change directory first, then start script.

Thanks.

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

Re: Wrapper script?

Thu May 06, 2021 11:27 pm

eureka moment.
works great
command && command2

thanks Tim !

Return to “Python”