Kodi Community Forum

Full Version: Quit and launch a windows program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there any way i can program an onclick button to do two actions.

1. Quit kodi
2. wait 1 or 2 seconds
3. launch a windows .exe

I need to quit kodi before i launch a windows exe.

thanks
I would put the logic in a batch file and call that from the onclick
So, you want an application (Kodi) that has already totally stopped running, still execute another Windows application, after 2-3 seconds of being already stopped. It sounds a bit like an act from beyond the grave to me. Pretty unlikely.
(2017-09-22, 15:33)BigNoid Wrote: [ -> ]I would put the logic in a batch file and call that from the onclick

That is exactly what i was going to do. however i do not know how to quit Kodi from a batch file. I do not want to use the windows kill command as it does not save the changes.

Thanks
Launch the batchfile first with a time delay, then close kodi.

Or run a check for kodi.exe @ https://stackoverflow.com/questions/1544...ess-exists
(2017-09-22, 16:00)badaas Wrote: [ -> ]Launch the batchfile first with a time delay, then close kodi.

Or run a check for kodi.exe @ https://stackoverflow.com/questions/1544...ess-exists

Nice!!!!!
I have something like this in a restart script.
See below for a working example.
Stick test.py wherever and run from a favourite / key / skin shortcut.
Stick test.bat in userdata/batch folder
Edit test.bat to the path of whatever .exe you want to start.

test.py:
Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import xbmc
import os
import subprocess
from subprocess import Popen

print 'running test.py'
USERDATA = xbmc.translatePath('special://masterprofile')
batchfolder = os.path.join(USERDATA, 'batch')
batchfile = os.path.join(batchfolder, 'test.bat')
assert os.path.isdir(batchfolder)
os.chdir(batchfolder)
subprocess.Popen('test.bat', close_fds=True,  shell=True)
xbmc.executebuiltin('Notification(Stopping, kodi)')
xbmc.sleep(1000)
xbmc.executebuiltin('Quit')
exit()
test.bat:
Code:
@ECHO OFF

rem temp add
Timeout /T 2 /Nobreak

:LOOP
tasklist | find /i "kodi" >nul 2>&1
IF ERRORLEVEL 1 (
  GOTO CONTINUE
) ELSE (
  ECHO Kodi is still running
  Timeout /T 2 /Nobreak
  GOTO LOOP
)

:CONTINUE
rem Timeout /T 2 /Nobreak
START "" "C:\Program Files\WinSCP\WinSCP.exe"

There may well be an easier way - that's what I ended up with.

edit: just realised we're in skinning, but the principle is the same.
Troggy, thank you very much i was looking for something like this for a long while.

worked like a charm. Running it using <onclick>RunScript(special://userdata/test.py)</onclick>

Created two different version:

1. quits and start kodi (could not get the builtin RestartApp function to work in windows)
2. quits and start explorer

Do you know off a way to first quit and then put computer to sleep. I could use your script and put the sleep function in batch. but wanted to know if there is anything better using python.
I've never looked at sleep - tbh I use libreelec for kodi 90% of the time - I'd probably do it via the batch file but that just means it's an obvious route, not that it's necessarily the best.
Glad it's done the job, anyway, and thanks for feeding back.