Kodi Community Forum

Full Version: special protocol & subprocess.popen
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hoping for some assistance because what I don't know about this subject would fill volumes. Smile

Trying to convert a working script with absolute paths:
Code:
p = subprocess.Popen(['python', 'g:/kodi/scripts/myscript.py'], stdout=subprocess.PIPE)
while True:
    line = p.stdout.readline()
    if line != b'':
        do_stuff()
    else:
        break

To one using special protocol:
Code:
from xbmcvfs import File
loc = "special://skin//scripts//myscript.py"
p = subprocess.Popen(['python', File(loc)], stdout=subprocess.PIPE)
while True:
    line = p.stdout.readline()
    if line != b'':
        do_stuff()
    else:
        break

The latter breaks with a 'argument of type 'xbmcvfs.File' is not iterable' error.

Any help would be greatly appreciated.
subprocess is a pure Python module and does not know anything about Kodi and its virtual filesystem. I'm afraid you cannot use them together. And xbmcvfs.File is indeed not an iterable object.
Thank you sir. Plan b it is... brute force.
You can use the following to translate the special path to the real filesystem path.
Code:
loc = xbmc.translatePath("special://skin//scripts//myscript.py")
(2018-05-06, 18:44)Rechi Wrote: [ -> ]You can use the following to translate the special path to the real filesystem path.
Code:
loc = xbmc.translatePath("special://skin//scripts//myscript.py")

Many thanks for this little gem. A real labor saver.
(2018-05-06, 18:44)Rechi Wrote: [ -> ]You can use the following to translate the special path to the real filesystem path.
Code:
loc = xbmc.translatePath("special://skin//scripts//myscript.py")
Note that it will work only for local paths, not networked ones.
Follow on question. Is there a way to invoke KODI's python interpreter in my subprocess call?
Kodi's interpreter does not exist as a standalone executable. There's RunScript builtin command that allows to launch separate scripts that are not addons.
There it is. Thank you.