Hi,
I'm completly new to Python. I've learned some languages at school and now I'm looking for way to program and customize RPI as I need for myself.
I'm planning to use RPi in my car as multimedia center. This Multimedia center has to have also possibility to control my cars ECU. I have Megasquirt ecu in my car and I'm looking for a way to run MegaTunix from XBMC main screen with one single click.
In order to do so I need to edit stock XBMC skin to make another button and clicking it leads to running MegaTunix.
Im looking for help from here.
Re: Running .sh program using python
@matzz: I know nothing about programming/extending XMBC but the `subprocess` module is the answer to the question (?) in the subject line of your post.
Code: Select all
while not self.asleep():
sheep += 1
Re: Running .sh program using python
Thank you, I'll try to look more into it soon. If I make any progress, I'll post it here also.
-
- Posts: 20
- Joined: Sun Sep 16, 2012 8:28 am
Re: Running .sh program using python
I don't know anything at all about programming XBMC, but if you want to automate shell commands in python, I can show you how to do that. There is a library for python called os that will do this (you may have to download it, I don't know as I haven't tried it on a raspi)
WIth that, you should be able to run shell commands within python. If you wanted to run a shell script in it, you would just enter, "sh NAME OF SHELL SCRIPT.sh". And that's pretty much all there is to it. Hope that this is of relevance, good luck with your project
.
Code: Select all
import os # Import the os library
os.system("SHELL COMMAND GOES INSIDE QUOTES")

Re: Running .sh program using python
Hi,
While os.system() works it is considered a bad pratice to use it and subprocess module should be used in favor of some of old os.* calls. Despite Python recommendations found in official documentation: http://docs.python.org/library/subprocess.html there is another great reason not to use it or at least be very carefull when you pass unvalidated/untrusted input to os.system(). Also please note that subprocess calls generally do not invoke shell unless shell=True is being used explicitly.
Here is a good writeup with examples regarding insecure use of os.system():
http://www.hpenterprisesecurity.com/vul ... ction.html
While os.system() works it is considered a bad pratice to use it and subprocess module should be used in favor of some of old os.* calls. Despite Python recommendations found in official documentation: http://docs.python.org/library/subprocess.html there is another great reason not to use it or at least be very carefull when you pass unvalidated/untrusted input to os.system(). Also please note that subprocess calls generally do not invoke shell unless shell=True is being used explicitly.
Here is a good writeup with examples regarding insecure use of os.system():
http://www.hpenterprisesecurity.com/vul ... ction.html
Re: Running .sh program using python
Hi,matzz wrote: I'm planning to use RPi in my car as multimedia center. This Multimedia center has to have also possibility to control my cars ECU. I have Megasquirt ecu in my car and I'm looking for a way to run MegaTunix from XBMC main screen with one single click.
You have a look to https://github.com/aboudou/raspiledmete ... er/main.py (starting line #52) to see how you may execute an external script, and check for the output.
https://goddess-gate.com/ - My main website
http://raspberrypi.goddess-gate.com/ - A website about (and hosted by) my Raspberry Pi
https://twitter.com/boudouarnaud - Follow me on Twitter
http://www.fablab-sud31.fr/ - Fab Lab Sud31-Val d'Ariège
http://raspberrypi.goddess-gate.com/ - A website about (and hosted by) my Raspberry Pi
https://twitter.com/boudouarnaud - Follow me on Twitter
http://www.fablab-sud31.fr/ - Fab Lab Sud31-Val d'Ariège