How can I capture stdout of external program
#1
Hi all,

I'm trying to write my first KODI addon.

I'd like to execute an external command (which already works successfully) but I'd like to display the output of the program/script.
I am using the following function:
 
Code:
xbmc.executebuiltin('System.Exec(/path/bin/program_or_script)')

How can I capture the output (stdout) of the program/script and assign it to a variable?

Unfortunately I didn't find an example for that.

Note that currently I'm using only these modules (and it would be nice if I wouldn't need others):
Code:
import xbmcaddon
import xbmcgui

Of course the return code of the external command would be also interesting Wink

Many thanks for help
Reply
#2
the system.exec() builtin command doesn't provide such functionality.

you can use the subprocess python library instead:
https://docs.python.org/2/library/subprocess.html
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
Subprocess doesn't work on Xbox version such it will break for that platform if you care about that
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#4
an alternative would be to try os.popen()
https://docs.python.org/2/library/os.html#os.popen
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

Logout Mark Read Team Forum Stats Members Help
How can I capture stdout of external program0