using an xbmc script to call unix commands and display them the results ?

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
schneidz Offline
Fan
Posts: 389
Joined: Jun 2009
Reputation: 0
Post: #1
hi, is it possible to run commands from within xbmc using a script.

would i be able to list the contents returned from ls by using this code:
Code:
xbmc.executebuiltin("XBMC.RunScript(ls,$HOME)")

is there a way to show the contents returned from ls by using os.system() within xbmc ?

thanks,
find quote
althekiller Offline
Team-XBMC Developer
Posts: 4,703
Joined: May 2004
Reputation: 12
Post: #2
You want os.popen().
find quote
Temhil Offline
Skilled Python Coder
Posts: 395
Joined: Apr 2008
Reputation: 1
Location: Canada
Smile    Post: #3
Here a function we did for the Installer Passion-XBMC script in order to list the content of a directory:

Code:
import os
def listDirFiles( path):
   """
   List the files of a directory
   @param path:
   """
   print "listDirFiles: content of directory: %s"%path
   dirList = os.listdir( str( path ) )

   return dirList

This will work on every OS including linux

[Image: passionxbmc_signature.png]
_____________________________

Repositories Installer: select and install unofficial repositories / TAC.TV: watch videos on TAC.TV
Installer Passion-XBMC: Download and Install Add-ons (pre-Dharma only)

[Image: project_thin_badge.gif]
find quote
Temhil Offline
Skilled Python Coder
Posts: 395
Joined: Apr 2008
Reputation: 1
Location: Canada
Post: #4
As althekiller said, if you want to get the STDOUT from the execution of external commands. Rather than use os.system(), use os.popen(), like so:
Code:
import os
stdout_handle = os.popen("echo something", "r")
text = stdout_handle.read()

[Image: passionxbmc_signature.png]
_____________________________

Repositories Installer: select and install unofficial repositories / TAC.TV: watch videos on TAC.TV
Installer Passion-XBMC: Download and Install Add-ons (pre-Dharma only)

[Image: project_thin_badge.gif]
find quote
schneidz Offline
Fan
Posts: 389
Joined: Jun 2009
Reputation: 0
Post: #5
^ thanks, i guess what i was looking for was something like a hello world example
find quote