Call another python script as root
#1
Hello,

I have to run a part of my addon code as root (monitoring GPIO pins on Raspberry Pi) so I tried to insert this to my default.py:
Code:
import os
os.system("sudo python x.py")
but as I see XBMC igore this call, x.py won't run. Tried without sudo, same result.
If I run default.py from command line it works fine, calls x.py.

In the log everything seems OK:
Code:
22:20:39 T:2945446976   DEBUG: Process - The source file to load is /home/pi/.xbmc/addons/script.module.gpio/default.py
22:20:39 T:2945446976   DEBUG: Process - Setting the Python path to /home/pi/.xbmc/addons/script.module.gpio:/opt/xbmc-bcm/xbmc-bin/share/xbmc/addons/script.module.simplejson/lib:/home/pi/.xbmc/addons/weather.wunderground/resources/lib/wunderground:/opt/xbmc-bcm/xbmc-bin/share/xbmc/addons/script.module.pil/lib:/opt/xbmc-bcm/xbmc-bin/share/xbmc/addons/script.module.pysqlite/lib:/usr/local/lib/python2.7/dist-packages/distribute-0.6.34-py2.7.egg:/usr/lib/python2.7:/usr/lib/python2.7/plat-linux2:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload:/usr/local/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages:
22:20:39 T:2945446976   DEBUG: Process - Entering source directory /home/pi/.xbmc/addons/script.module.gpio
22:20:39 T:2945446976   DEBUG: Instantiating addon using automatically obtained id of "gpio" dependent on version 2.1.0 of the xbmc.python api
22:20:40 T:2945446976    INFO: Scriptresult: Success
22:20:40 T:2945446976    INFO: Python script stopped
22:20:40 T:2945446976   DEBUG: Thread XBPyThread 2945446976 terminating
22:20:40 T:3037437952   DEBUG: waiting for python thread 3 (/home/pi/.xbmc/addons/script.module.gpio/default.py) to stop
22:20:40 T:3037437952   DEBUG: python thread 3 (/home/pi/.xbmc/addons/script.module.gpio/default.py) destructed

Thanks,
Reply
#2
(2013-01-12, 00:49)oldmobil Wrote: Hello,

I have to run a part of my addon code as root (monitoring GPIO pins on Raspberry Pi) so I tried to insert this to my default.py:
Code:
import os
os.system("sudo python x.py")
but as I see XBMC igore this call, x.py won't run. Tried without sudo, same result.
If I run default.py from command line it works fine, calls x.py.

In the log everything seems OK:
Code:
22:20:39 T:2945446976   DEBUG: Process - The source file to load is /home/pi/.xbmc/addons/script.module.gpio/default.py
22:20:39 T:2945446976   DEBUG: Process - Setting the Python path to /home/pi/.xbmc/addons/script.module.gpio:/opt/xbmc-bcm/xbmc-bin/share/xbmc/addons/script.module.simplejson/lib:/home/pi/.xbmc/addons/weather.wunderground/resources/lib/wunderground:/opt/xbmc-bcm/xbmc-bin/share/xbmc/addons/script.module.pil/lib:/opt/xbmc-bcm/xbmc-bin/share/xbmc/addons/script.module.pysqlite/lib:/usr/local/lib/python2.7/dist-packages/distribute-0.6.34-py2.7.egg:/usr/lib/python2.7:/usr/lib/python2.7/plat-linux2:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload:/usr/local/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages:
22:20:39 T:2945446976   DEBUG: Process - Entering source directory /home/pi/.xbmc/addons/script.module.gpio
22:20:39 T:2945446976   DEBUG: Instantiating addon using automatically obtained id of "gpio" dependent on version 2.1.0 of the xbmc.python api
22:20:40 T:2945446976    INFO: Scriptresult: Success
22:20:40 T:2945446976    INFO: Python script stopped
22:20:40 T:2945446976   DEBUG: Thread XBPyThread 2945446976 terminating
22:20:40 T:3037437952   DEBUG: waiting for python thread 3 (/home/pi/.xbmc/addons/script.module.gpio/default.py) to stop
22:20:40 T:3037437952   DEBUG: python thread 3 (/home/pi/.xbmc/addons/script.module.gpio/default.py) destructed

Thanks,

You might need to state absolute path for the the x.py script.
Reply
#3
(2013-01-12, 07:23)giftie Wrote: You might need to state absolute path for the the x.py script.

Hello, I tried it, but exactly same result :-(
Code:
import os
os.system("sudo python /home/pi/.xbmc/addons/script.module.gpio/x.py")

os.system call from default.py with other sudo bash commands works fine.

Thanks,
Reply

Logout Mark Read Team Forum Stats Members Help
Call another python script as root0