Linux Coding addon to execute external commands
#1
Question 
Hi all

I want to code a small addon that executes a command (for example "reboot" or "apt-get update"). I tried to read the wiki and download the HelloWorld addon. I know Python, but I can't find how to run comands or externals scripts.sh via kodi-addon. Every tutorial I read speak about xbmc and gui classes, but I want something more simple: Just a button that invoke one hardcoded command.

Con somebody give me a clue?

(Sorry for my english, this is not my nativa languaje)
Reply
#2
kodi offers a way to execute shell commands:
Code:
import xbmc

xbmc.executebuiltin('System.Exec(reboot)')

but there are various other python ways to do it as well:
http://stackoverflow.com/questions/89228...-in-python
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#3
Thanks! I will try subprocess.call, os.system and xbmc.executebuiltin and see differences. I also want to stop or exit Kodi before the command get executed.
Reply
#4
(2016-01-16, 01:53)ronie Wrote: kodi offers a way to execute shell commands:
Code:
import xbmc

xbmc.executebuiltin('System.Exec(reboot)')

but there are various other python ways to do it as well:
http://stackoverflow.com/questions/89228...-in-python

Excellent! It works like a charm! Now, the final part. I want to exit/quit Kodi at the end of the script. What command should I use?
Reply
#5
(2016-01-16, 02:13)aikoncwd Wrote: Excellent! It works like a charm! Now, the final part. I want to exit/quit Kodi at the end of the script. What command should I use?

This should work:
Code:
import xbmc
xbmc.executebuiltin('XBMC.Quit')
Reply
#6
(2016-01-16, 02:46)curti Wrote: This should work:
Code:
import xbmc
xbmc.executebuiltin('XBMC.Quit')

Nice, that code works, but I'm having unespected results Sad I will try to explain what I want to make...

I want a simple button (a program addon), when you launch the addon then execute "emulationstation" command (to launch RetroPie GUI). This works, but if you don't exit Kodi before emulationstation, then the image gets distorsioned and all input events from the controller are captured by Kodi. So I tried this:

Code:
import xbmc
import os, sys

xbmc.executebuiltin('XBMC.Quit')
os.system("sh games.sh")

Inside games.sh I have "emulationstation" command. But don't works Sad
I tried to add this inside games.sh:

Code:
kodi-send --action="Quit"
emulationstation

But don't works. If I run this games.sh from a SSH console then all works as expected. But if the same games.sh is executed by kodi, then emulationstation gets glitched and have no input-events control.

Any ideas to solve that? I think there will be a better/easy way to code this

EDIT: I tried to killall kodi.bin, but kodi re-launch itself after killall lol
Reply
#7
this doesn't work cause closing kodi also closes your python interpreter and therefore your script/addon.

A possible solution might be to suspend kodi from within your games.sh script by sending it a SIGSTOP signal(kill -19) and SIGCONT(kill -18) to resume after.

Other then that, did you try advanced launcher?
Reply
#8
(2016-01-16, 10:54)wsnipex Wrote: this doesn't work cause closing kodi also closes your python interpreter and therefore your script/addon.

A possible solution might be to suspend kodi from within your games.sh script by sending it a SIGSTOP signal(kill -19) and SIGCONT(kill -18) to resume after.

Other then that, did you try advanced launcher?

Did not work

games.sh
Code:
pgrep kodi.bin | xargs kill -19
emulationstation
pgrep kodi.bin | xargs kill -18

Kodi process get suspended, but emulationstation can't run with that method (screen blinks black and don't react to controller events). If I use this:

games.sh
Code:
kodi-send --action="Quit"
emulationstation

and invoke this SH from the command line (outside kodi) all works as expected. But If I invoke this SH from Kodi, the blink effect/no-controller appears. I tried other addons like AdvancedLauncher or Executor, and I get the same results Sad
Reply
#9
perhaps you need to add some sleep between the two commands?

Code:
kodi-send --action="Quit"
sleep 1
emulationstation
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#10
@ronie Don't work Sad I tried with bigger sleep, but Kodi dont start "quitting" after games.sh is finished.
Killing kodi.bin process can do the trick, but after "killall kodi.bin" kodi re-launch itself. Is there any way to make a killall command and avoid kodi restart itself again?
Reply
#11
Well, I finally did something different but it works!

I editet kodi-standalone script and added emulationstation at the end. So now, I only need to exit Kodi and emulationstation will launch automatic. Smile
Reply

Logout Mark Read Team Forum Stats Members Help
Coding addon to execute external commands0