exit xbmc from script

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
bugme Offline
Banned
Posts: 73
Joined: Mar 2008
Post: #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
find quote
kraqh3d Offline
Retired Developer
Posts: 7,183
Joined: Dec 2003
Reputation: 4
Location: New York City, USA
Post: #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.
(This post was last modified: 2008-07-07 21:37 by kraqh3d.)
find quote
rodalpho Offline
Fan
Posts: 549
Joined: Nov 2006
Reputation: 16
Post: #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
find quote
bugme Offline
Banned
Posts: 73
Joined: Mar 2008
Post: #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.
find quote
bugme Offline
Banned
Posts: 73
Joined: Mar 2008
Post: #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')
find quote
kraqh3d Offline
Retired Developer
Posts: 7,183
Joined: Dec 2003
Reputation: 4
Location: New York City, USA
Post: #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.
find quote
bugme Offline
Banned
Posts: 73
Joined: Mar 2008
Post: #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
find quote
rodalpho Offline
Fan
Posts: 549
Joined: Nov 2006
Reputation: 16
Post: #8
Happy to help!
find quote
bugme Offline
Banned
Posts: 73
Joined: Mar 2008
Post: #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.
find quote
bugme Offline
Banned
Posts: 73
Joined: Mar 2008
Post: #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
find quote
Post Reply