Search code examples
pythonshellcronraspbian

Launching an external GUI application from Python via crontab


Good afternoon!

I have a need in Raspbian to run a GUI application using a telegram bot (Python). Running the application works like this:

p = Popen (["/home/pi/Downloads/reaper_linux_armv7l/REAPER/reaper"], stdout = PIPE, stderr = STDOUT)

There is one problem. If the bot was launched from crontab at system boot (@reboot), then the external application runs in the background. It works in the background, but I can't see its interface through realVNC.

If the bot was launched manually (without crontab), then everything is fine, in which case I can see the interface of the application being launched.

Can you please tell me how launching a Python bot through crontab affects whether the application is launched in the background or not, and how can this be controlled?


Solution

  • Cron run in a specific environment, without display manager. If you try to do a echo $DISPLAY return null. You need to set DISPLAY in your command, like that:

    * * * * * DISPLAY=:0 <YOUR-COMMAND>
    

    if your display is not 0, you can find, in X server with ps aux | grep Xorg