exit xbmc from script
#1
Hi, I have a small question. Googled for ages, no luck.

Explenation (skip this if you're in a hurry):

I have an older P3 800MHz running XBMC through Xubuntu. I can watch video just fine. I also use ZSNES, which runs fine. I created this extremely complicated script to run ZSNES from XBMC:
Code:
import os
os.system('zsnes')
With the script in my favorites I can run/quit the emulatoir without manually exitting and restarting XBMC. But this way. the emulator runs crappy while running it stand-alone runs it smoothly.

Question:
Can I simply exit xbmc from a python script started from xbmc, and restart it when the started app (zsnes) is finished? Or does someone have another suggestion for getting this behaviour to work?

Thanks
Reply
#2
there is a builtin command that can be executed to shutdown xbmc, but i'm not sure how python works in xbmc linux. i'm assuming the internal interpretter will be used which leads me to believe that nothing after that line will run.

so i think you need to call an external script that will be run by an external interpretter before closing xbmc. then that script can launch zsnes and then restart xbmc on close.

** edit **

moved to the linux forum. hopefully someone will have more info there.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#3
Something like this should work.

Python script:
Code:
import os
os.system('/path/to/runzsnes.sh')

runzsnes.sh:
Code:
#!/bin/bash

# Test to see if XBMC is running first
if ps -ef|grep -v grep|grep -i xbmc.bin
then
# Try a clean kill
ps aux|grep -i youruser|grep -v grep|grep -i xbmc.bin|awk '{print $2}'|xargs kill
echo `date` "Killed XBMC! (soft)" >> /tmp/killXBMC.log
else
echo "XBMC already dead! (soft)"
exit
fi

# takes a second or two to die with the soft kill
sleep 2

# Test to see if it's still running
if ps -ef|grep -v grep|grep -i xbmc.bin
then
# If it's still around, kill it -9
ps aux|grep -i youruser|grep -v grep|grep -i xbmc.bin|awk '{print $2}'|xargs kill -9
echo `date` "Killed XBMC! (hard)" >> /tmp/killXBMC.log
else
echo "XBMC already dead! (hard)"
exit
fi

# start xsnes
/path/to/xsnes

# start xbmc back up
/path/to/xbmc.bin
Reply
#4
Thanks a bunch, rodalpho!

Here's how I used it.

/home/xbmc/.xbmc/scripts/My Scripts/zsnes.py:

/home/xbmc/xbmc/zsnes.sh:
Code:
#!/bin/bash
# temporarily quit XBMC for ZSNES
# 07-07-2008
# Tx to rodalpho
# http://forum.xbmc.org/showthread.php?tid=34635

# Is XBMC running?
if ps -ef|grep -v grep|grep -i xbmc.bin
then
# Try a clean kill
ps aux|grep -i xbmc|grep -v grep|grep -i xbmc.bin|awk '{print $2}'|xargs kill
else
echo "This script should only be run from within XBMC."
fi

# Wait for the kill
sleep 2

# Is XBMC still running?
if ps -ef|grep -v grep|grep -i xbmc.bin
then
# If it's still around, kill it -9
ps aux|grep -i `logname`|grep -v grep|grep -i xbmc.bin|awk '{print $2}'|xargs kill -9
fi

# Start ZSNES
zsnes

# Done? Restart XBMC
xbmc

It works! Only thing I don't get is why I cannot use `logname` in stead of actually typing in my username.
Reply
#5
Not very interesting, but since I'm too blind to find the EDIT button, this was what the other line was supposed to say:

/home/xbmc/.xbmc/scripts/My Scripts/zsnes.py:
Code:
import os
#os.system('zsnes') # just in case
os.system('/home/xbmc/xbmc/zsnes.sh')
Reply
#6
i dont know but `whoami` seems to work just fine.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#7
One more thing, might be interesting for people trying to do the same thing.
I don know why, but from python I can just boot zsnes. But if I use this trick to kill xbmc first, the sound is gone. I googled for sound problems, and somehow this fixes it:
Code:
# Start ZSNES
zsnes -ad sdl
Reply
#8
Happy to help!
Reply
#9
Um, sorry, no it does not. It fixes the sound if you run zsnes from a command prompt, but not from within xbmc. I confused.

And I wouldn't have made such a mess if I knew how to edit my own posts. Sorry.
Reply
#10
kraqh3d Wrote:i dont know but `whoami` seems to work just fine.
I just tried it, and you are right! `logname` also works, so I hate to admit that it was probably a typo on my end heheh..

whoami.. didn't know that one Smile
Reply
#11
Ok I sorted it out. Here's a summary of strange behaviour:

$ zsnes (from command line) Works without sound
$ zsnes -ad sdl (from command line) Works
$ xbmc (from command line) Works
zsnes (from script.sh in xbmc) Works without sound
zsnes -ad sdl (from script.sh called by xbmc) Works without sound
xbmc (from script.sh called by (now killed) xbmc) Works without sound (??)

with script.sh being called from the above mentioned python script.

Anyone got a clue why this happens?
Reply
#12
Could it be related to something in the shell you use at the commandline compared to the shell used by sh when running your script?
Reply
#13
Would it not be simpler just to convert emuLauncher script into a plugin for XBMC?
http://forum.xbmc.org/showthread.php?tid=32186
http://forum.xbmc.org/showthread.php?tid=30659
http://forum.xbmc.org/showthread.php?tid=33970
http://forum.xbmc.org/showthread.php?tid=32150

Nuka1196 and spiff from Team-XBMC are working on a such plugin (and the changes need in XBMC to make it happen), I do not however know the progress they made on this.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#14
I use linux for quite some time now but it can still surprise me. So the correct answer would be: Not that I know of.

This is how I directly enter it in the xfce4-terminal virtual console. Or when I create a launcher on my desktop. Or when I run it using alt+f2 dialog.

So I was thinking, could this be related to something xbmc changes for sh that's not changed in a normal commandline?
Reply
#15
Hey Gamester17 I didn't read your reply yet, but it sounds like a splendid idea. I will have to read through these topics but if it has xbmc running in the background I will have the same problem as why I wanted to script-exit xbmc in the first place. (This old computer cannot handle too much at the same time.)
Reply

Logout Mark Read Team Forum Stats Members Help
exit xbmc from script0