Brief
I am a beginner at raspberry-pi and am currently working on a project, which requires to run a python script at boot.
A part of the script will check for some conditions and then open the chromium-browser (using subprocess.Popen()), if necessary.
Codes
Below is the short extract of my python script (the sleep is for me to check that the script is running):
import shlex, subprocess
import time
command = '/usr/bin/chromium-browser "https://www.google.com" -start-maximized --no-sandbox'
args = shlex.split(command)
browser = subprocess.Popen(args)
time.sleep(1000)
The code seems to be executed correctly when I am running from the Terminal:
python /home/pi/Desktop/test_popen_browser.py
However, when I try to schedule it on the crontab (edited using Terminal with the "sudo crontab -e" command), it does not seem to work (the python script is being executed, but no browser window is opened):
@reboot python /home/pi/Desktop/test_popen_browser.py &
Question
Have tried to search online for answers, and I think the environment variables are causing the problems. But I just cant find out what exactly should I set the environment variables to be.
Does anyone knows where the problem lies?
Thank you in advanced!
The problem is the GUI manager has not started when your script is started at reboot. Instead of running your script as cronjob place it in /home/pi/.config/lxsession/LXDE-pi/autostart
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver -no-splash
@point-rpi
/usr/bin/python /home/pi/Desktop/test_popen_browser.py
unclutter -idle 30
Good Luck!