def tarfile(tarfile, fname=None, asfile=None): if tarfile[-1] == 'z': compressed = 'z' else: compressed = '' if fname is None: if compressed: cmd = 'gunzip < %s | tar tf - 2>/dev/null' % tarfile else: cmd = 'tar tf - <%s 2>/dev/null' % tarfile fp = posix.popen(cmd, 'r') l = [] for line in fp.readlines(): if len(line) == 0: break l.append(line[0:-1]) fp.close() return l else: if compressed: cmd = 'gunzip < %s | tar xfO - %s 2>/dev/null' % (tarfile, fname) else: cmd = 'tar xfO - %s <%s 2>/dev/null' % (fname, tarfile) fp = posix.popen(cmd, 'r') if asfile: return fp data = fp.read() fp.close() if len(data) == 0: return None else: return data
def ask(question, default, filecheck = 1, type = 'file', locate = ''): done = 0 print "-------------------------------------------------------------------" while not done: print question if (locate) and not useDefaults: pipe = popen("locate %s | head -1 " % locate ) default = pipe.readline().strip() print 'Default = [' + default + ']: ', if useDefaults or useLocates: retval = "" else: retval = raw_input() if retval == "": retval = default if retval == 'none': done = 1 elif not filecheck: done = 1 elif useDefaults or useLocates or file_exists(retval, type): done = 1 else: print "WARNING: '%s' does not exist, or wrong type (file or dir)!" % retval if retval == 'none': return '' else: return retval
def ask(question, default, filecheck=1, type='file', locate=''): done = 0 print "-------------------------------------------------------------------" while not done: print question if (locate) and not useDefaults: pipe = popen("locate %s | head -1 " % locate) default = pipe.readline().strip() print 'Default = [' + default + ']: ', if useDefaults or useLocates: retval = "" else: retval = raw_input() if retval == "": retval = default if retval == 'none': done = 1 elif not filecheck: done = 1 elif useDefaults or useLocates or file_exists(retval, type): done = 1 else: print "WARNING: '%s' does not exist, or wrong type (file or dir)!" % retval if retval == 'none': return '' else: return retval
def main(): delay = DEF_DELAY # XXX Use getopt() later try: thisuser = posix.environ['LOGNAME'] except: thisuser = posix.environ['USER'] printers = sys.argv[1:] if printers: # Strip '-P' from printer names just in case # the user specified it... for i in range(len(printers)): if printers[i][:2] == '-P': printers[i] = printers[i][2:] else: if posix.environ.has_key('PRINTER'): printers = [posix.environ['PRINTER']] else: printers = [DEF_PRINTER] # clearhome = posix.popen('clear', 'r').read() # while 1: text = clearhome for name in printers: text = text + makestatus(name, thisuser) + '\n' print text time.sleep(delay)
def simplify(value,units): if units==None: return value,None # Easy! a=posix.popen("/usr/bin/units -o %%.15g '%f %s'" % (value,units),"r") (v,u)=a.readline().strip().split(" ",1)[1].strip().split(" ",1) v=float(v) return v,u
def ask(question, default, filecheck = 1, type = 'file', locate = ''): done = 0 print "-------------------------------------------------------------------" while not done: print question if (locate) and not useDefaults: print "Looking for '%s'..." % locate pipe = popen("locate \"%s\" 2> /dev/null" % locate ) new_default = pipe.readline() new_default = new_default.strip() if new_default: default = new_default pipe.close() print 'Default = [' + default + ']: ', if useDefaults or useLocates: retval = "" else: retval = raw_input() if retval == "": retval = default if retval == 'none': done = 1 elif not filecheck: done = 1 elif useDefaults or useLocates or file_exists(retval, type): done = 1 else: print "WARNING: '%s' does not exist, or wrong type (file or dir)!" % retval if retval == 'none': return '' else: return retval
def get_clipboard_data(self,isTranslateNow): """ get selection text use clipboard """ isTranslateNow=isTranslateNow.data self.popUpFrame.view.Hide() if not isTranslateNow: self.popUpFrame.showFrame=False config.countClickUp=0 if os.name=="posix": try: time.sleep(0.1) text = popen('xsel').read() config.isRunTranslate=True self.popUpFrame.dataText = text if self.popUpFrame.dataText!="": if isTranslateNow: config.countClickUp=1 self.popUpFrame.translate() else: self.popUpFrame.view.Show() self.dblCtrl=0 except Exception, ex: self.popUpFrame.dataText=ex.message.encode('utf-8') self.popUpFrame.view.Show()
def legacy_shell_injections(input): """ Numerous legacy APIs for shells in Python stdlib """ os.system(input) os.popen(input) os.popen2(input) os.popen3(input) os.popen4(input) posix.system(input) posix.popen(input) popen2.popen2(input) popen2.popen3(input) popen2.popen4(input) popen2.Popen3(input) popen2.Popen4(input) commands.getoutput(input) commands.getstatusoutput(input)
def __init__(self, fname, filter=None, status=None, threaded=None): flist = string.split(fname, '+') if len(flist) > 1: import posix if flist[0][-3:] == '.gz': cmd = 'gunzip -c %s ' % string.join(flist,' ') else: cmd = 'cat %s ' % string.join(flist,' ') self.fp = posix.popen(cmd, 'r') sys.stderr.write('compositing: %s\n' % fname) self.fname = fname elif fname[-3:] == '.gz': # it appears MUCH faster to open a pipe to gunzip # than to use the zlib/gzip module.. import posix self.fp = posix.popen('gunzip <%s' % fname, 'r') sys.stderr.write('decompressing: %s\n' % fname) self.fname = fname[:-3] self.zfname = fname[:] elif not posixpath.exists(fname) and \ posixpath.exists(fname+'.gz'): import posix # if .gz file exists and the named file does not, # try using the .gz file instead... self.fname = fname self.zfname = fname+'.gz' self.fp = posix.popen('gunzip <%s' % self.zfname, 'r') sys.stderr.write('decompressing: %s\n' % self.zfname) else: self.fname = fname self.zfname = None self.fp = open(self.fname, 'r') self.cache = [] self.status = status self.filter = filter self.userparams = None self.threaded = threaded self.taskname = None self.extradata = [] if self.threaded: self._lock = thread.allocate_lock() self.backload() else: self._lock = None
def __init__(self, fname, filter=None, status=None, quiet=None): flist = string.split(fname, '+') if len(flist) > 1: if flist[0][-3:] == '.gz': cmd = 'gunzip --quiet -c %s ' % string.join(flist, ' ') else: cmd = 'cat %s ' % string.join(flist, ' ') self.fp = posix.popen(cmd, 'r') if not quiet: sys.stderr.write('compositing: %s\n' % fname) self.fname = fname elif fname[-3:] == '.gz': # it appears MUCH faster to open a pipe to gunzip # than to use the zlib/gzip module.. self.fp = posix.popen('gunzip --quiet <%s 2>/dev/null' % fname, 'r') if not quiet: sys.stderr.write('decompressing: %s\n' % fname) self.fname = fname[:-3] self.zfname = fname[::] elif not posixpath.exists(fname) and \ posixpath.exists(fname+'.gz'): # if .gz file exists and the named file does not, # try using the .gz file instead... self.fname = fname self.zfname = fname + '.gz' self.fp = posix.popen( 'gunzip --quiet <%s 2>/dev/null' % self.zfname, 'r') if not quiet: sys.stderr.write('decompressing: %s\n' % self.zfname) else: self.fname = fname self.zfname = None self.fp = open(self.fname, 'r') self.cache = [] self.status = status self.filter = filter self.userparams = None self.taskname = None self.extradata = [] self.counter = 0
def __init__(self, fname, filter=None, status=None, quiet=None): flist = string.split(fname, '+') if len(flist) > 1: if flist[0][-3:] == '.gz': cmd = 'gunzip --quiet -c %s ' % string.join(flist,' ') else: cmd = 'cat %s ' % string.join(flist,' ') self.fp = posix.popen(cmd, 'r') if not quiet: sys.stderr.write('compositing: %s\n' % fname) self.fname = fname elif fname[-3:] == '.gz': # it appears MUCH faster to open a pipe to gunzip # than to use the zlib/gzip module.. self.fp = posix.popen('gunzip --quiet <%s 2>/dev/null' % fname, 'r') if not quiet: sys.stderr.write('decompressing: %s\n' % fname) self.fname = fname[:-3] self.zfname = fname[::] elif not posixpath.exists(fname) and \ posixpath.exists(fname+'.gz'): # if .gz file exists and the named file does not, # try using the .gz file instead... self.fname = fname self.zfname = fname+'.gz' self.fp = posix.popen('gunzip --quiet <%s 2>/dev/null' % self.zfname, 'r') if not quiet: sys.stderr.write('decompressing: %s\n' % self.zfname) else: self.fname = fname self.zfname = None self.fp = open(self.fname, 'r') self.cache = [] self.status = status self.filter = filter self.userparams = None self.taskname = None self.extradata = [] self.counter = 0
def client(hostname): print 'client starting' cmd = 'rsh ' + hostname + ' "cd ' + AUDIODIR cmd = cmd + '; DISPLAY=:0; export DISPLAY' cmd = cmd + '; ' + PYTHON + ' intercom.py -r ' for flag in debug: cmd = cmd + flag + ' ' cmd = cmd + gethostname() cmd = cmd + '"' if debug: print cmd pipe = posix.popen(cmd, 'r') ack = 0 nak = 0 while 1: line = pipe.readline() if not line: break sys.stdout.write('remote: ' + line) if line == 'NAK\n': nak = 1 break elif line == 'ACK\n': ack = 1 break if nak: print 'Remote user doesn\'t want to talk to you.' return if not ack: print 'No acknowledgement (remote side crashed?).' return # print 'Ready...' # s = socket(AF_INET, SOCK_DGRAM) s.bind('', PORT2) # otheraddr = gethostbyname(hostname), PORT1 try: try: ioloop(s, otheraddr) except KeyboardInterrupt: log('client got intr') except error: log('client got error') finally: s.sendto('', otheraddr) log('client finished sending empty packet to server') # log('client exit') print 'Done.'
def expandvars(path): if '$' not in path: return path q = '' for c in path: if c in ('\\', '"', '\'', '`'): c = '\\' + c q = q + c d = '!' if q == d: d = '+' p = posix.popen('cat <<' + d + '\n' + q + '\n' + d + '\n', 'r') res = p.read() del p if res[-1:] == '\n': res = res[:-1] return res
def get_host_address(): """ try to get determine the interface used for the default route, as this is most likely the interface we should bind to (on a single homed host!) """ import sys if sys.platform == 'win32': if have_netifaces: interfaces = netifaces.interfaces() if len(interfaces): return get_ip_address(interfaces[0]) # on windows assume first interface is primary else: try: route_file = '/proc/net/route' route = open(route_file) if(route): tmp = route.readline() #skip first line while (tmp != ''): tmp = route.readline() l = tmp.split('\t') if (len(l) > 2): if l[2] != '00000000': #default gateway... route.close() return get_ip_address(l[0]) except IOError, msg: """ fallback to parsing the output of netstat """ from os import uname import posix (osname,_, _, _,_) = uname() osname = osname.lower() f = posix.popen('netstat -rn') lines = f.readlines() f.close() for l in lines: parts = [x.strip() for x in l.split(' ') if len(x) > 0] if parts[0] in ('0.0.0.0','default'): if osname[:6] == 'darwin': return get_ip_address(parts[5]) else: return get_ip_address(parts[-1]) except Exception, msg: import traceback traceback.print_exc()
def main(): if len(sys.argv) <> 2: sys.stderr.write('usage: ' + sys.argv[0] + ' hostname\n') sys.exit(2) hostname = sys.argv[1] cmd = 'exec rsh </dev/null ' + hostname + \ ' "cd /ufs/guido/mm/demo/audio; ' + \ 'exec /ufs/guido/bin/sgi/python record.py"' pipe = posix.popen(cmd, 'r') config = al.newconfig() config.setchannels(AL.MONO) config.setqueuesize(QSIZE) port = al.openport('', 'w', config) while 1: data = pipe.read(BUFSIZE) if not data: sts = pipe.close() sys.stderr.write(sys.argv[0] + ': end of data\n') if sts: sys.stderr.write('rsh exit status '+`sts`+'\n') sys.exit(1) port.writesamps(data) del data
def output(cmd, strip=None): """Run a command and collect all output""" try: # Python 2.x stdin, stdout = os.popen4(cmd) assert(not stdin.close()) except AttributeError: try: # Python 1.x on Unix import posix stdout = posix.popen('%s 2>&1' % cmd) except ImportError: # Python 1.x on Windows (no cygwin) # There's no easy way to collect output from stderr, so we'll # just collect stdout. stdout = os.popen(cmd) output = stdout.read() assert(not stdout.close()) if strip: return string.strip(output) else: return output
def main(): if len(sys.argv) <> 2: sys.stderr.write('usage: ' + sys.argv[0] + ' hostname\n') sys.exit(2) hostname = sys.argv[1] cmd = 'exec rsh </dev/null ' + hostname + \ ' "cd /ufs/guido/mm/demo/audio; ' + \ 'exec /ufs/guido/bin/sgi/python record.py"' pipe = posix.popen(cmd, 'r') config = al.newconfig() config.setchannels(AL.MONO) config.setqueuesize(QSIZE) port = al.openport('', 'w', config) while 1: data = pipe.read(BUFSIZE) if not data: sts = pipe.close() sys.stderr.write(sys.argv[0] + ': end of data\n') if sts: sys.stderr.write('rsh exit status ' + ` sts ` + '\n') sys.exit(1) port.writesamps(data) del data
class BadDeviceState: def __init__(self, msg): self.msg=msg def __repr__(self): return "<BadDeviceState: " + self.msg + ">" def checkStat(raidstat): devLines=filter(lambda s: s.find("SPYRAID") > 0, raidstat) assert(len(devLines) == 4) for l in devLines: a=l.split() state=a[-2] if state != 'Normal': raise BadDeviceState(state) if __name__ == '__main__': f=posix.popen("/sbin/sysctl hpt374.status") raidstat=f.readlines() f.close() try: checkStat(raidstat) except: traceback.print_exc() if raidstat is not None: sys.stderr.write("\n\n RAID Status:\n\n") sys.stderr.writelines(raidstat)
#! /usr/bin/env python
def convert(value,from_unit,to_unit): a=posix.popen("/usr/bin/units -o %%.15g '%f %s' '%s'" % (value,from_unit,to_unit),"r") return float(a.readline().strip().split(" ",1)[1].strip())
def __init__(self, msg): self.msg = msg def __repr__(self): return "<BadDeviceState: " + self.msg + ">" def checkStat(raidstat): devLines = filter(lambda s: s.find("SPYRAID") > 0, raidstat) assert len(devLines) == 4 for l in devLines: a = l.split() state = a[-2] if state != "Normal": raise BadDeviceState(state) if __name__ == "__main__": f = posix.popen("/sbin/sysctl hpt374.status") raidstat = f.readlines() f.close() try: checkStat(raidstat) except: traceback.print_exc() if raidstat is not None: sys.stderr.write("\n\n RAID Status:\n\n") sys.stderr.writelines(raidstat)
from posix import popen import os __author__ = "Douglas Blank <*****@*****.**>" __version__ = "$Revision: 1.27 $" if "--version" in map(lambda s: s[0:9], sys.argv): for command in sys.argv: if command[0:9] == "--version": com, pyverSuggest = command.split("=", 2) else: print "Checking for versions of Python..." versions = [("python", "")] for i in range(22, 41): pyver = "python%.1f" % (i / 10.0) pipe = popen("which %s 2> /dev/null" % pyver ) which = pipe.readline().strip() if which == '': pass else: versions.append((pyver, pyver[-3:])) pyverSuggest = versions[-1][1] prefix = "/usr" if "--prefix" in map(lambda s: s[0:8], sys.argv): for command in sys.argv: if command[0:8] == "--prefix": com, prefix = command.split("=", 2) if "--defaults" in sys.argv: useDefaults = 1
from posix import popen import os __author__ = "Douglas Blank <*****@*****.**>" __version__ = "$Revision: 1.27 $" if "--version" in map(lambda s: s[0:9], sys.argv): for command in sys.argv: if command[0:9] == "--version": com, pyverSuggest = command.split("=", 2) else: print "Checking for versions of Python..." versions = [("python", "")] for i in range(22, 41): pyver = "python%.1f" % (i / 10.0) pipe = popen("which %s 2> /dev/null" % pyver) which = pipe.readline().strip() if which == '': pass else: versions.append((pyver, pyver[-3:])) pyverSuggest = versions[-1][1] prefix = "/usr" if "--prefix" in map(lambda s: s[0:8], sys.argv): for command in sys.argv: if command[0:8] == "--prefix": com, prefix = command.split("=", 2) if "--defaults" in sys.argv: useDefaults = 1
# intercom -- use mike and headset to *talk* to a person on another host.
def makestatus(name, thisuser): pipe = posix.popen('lpq -P' + name + ' 2>&1', 'r') lines = [] users = {} aheadbytes = 0 aheadjobs = 0 userseen = 0 totalbytes = 0 totaljobs = 0 color = c_unknown while 1: line = pipe.readline() if not line: break fields = string.split(line) n = len(fields) if len(fields) >= 6 and fields[n-1] == 'bytes': rank = fields[0] user = fields[1] job = fields[2] files = fields[3:-2] bytes = eval(fields[n-2]) if user == thisuser: userseen = 1 if aheadjobs == 0: color = c_ontop elif not userseen: aheadbytes = aheadbytes + bytes aheadjobs = aheadjobs + 1 totalbytes = totalbytes + bytes totaljobs = totaljobs + 1 if color == c_unknown: color = c_smallqueue elif color == c_smallqueue: color = c_bigqueue if users.has_key(user): ujobs, ubytes = users[user] else: ujobs, ubytes = 0, 0 ujobs = ujobs + 1 ubytes = ubytes + bytes users[user] = ujobs, ubytes else: if fields and fields[0] <> 'Rank': line = string.strip(line) if line == 'no entries': line = name + ': idle' if color == c_unknown: color = c_idle elif line[-22:] == ' is ready and printing': line = line[:-22] else: line = name + ': ' + line color = c_error lines.append(line) # if totaljobs: line = `(totalbytes+1023)/1024` + ' K' if totaljobs <> len(users): line = line + ' (' + `totaljobs` + ' jobs)' if len(users) == 1: line = line + ' for ' + users.keys()[0] else: line = line + ' for ' + `len(users)` + ' users' if userseen: if aheadjobs == 0: line = line + ' (' + thisuser + ' first)' else: line = line + ' (' + `(aheadbytes+1023)/1024` line = line + ' K before ' + thisuser + ')' lines.append(line) # sts = pipe.close() if sts: lines.append('lpq exit status ' + `sts`) color = c_error return string.joinfields(lines, ': '), color
hand_eval = deal['hand_eval'] # We only qualify for the progressive pot if we bet 5 credits if (credits_per_game == 5): progressive_jackpot = progressive_jackpot / 10000.0 + 4000 else: progressive_jackpot = 4000 cards = reduce((lambda a, b: a + ' ' + b), cards) try: print "game_id: %s; hand: %s" % (game_id, hand_names[hand_eval]) except: print "oops!" command = "./jacks %s %s" % (progressive_jackpot, cards) result = posix.popen(command).readlines() for line in result: print " : %s" % (line[:-1], ) holds = string.split(result[-1][:-1])[0] hold = bvc.videopoker_hold(game_id, holds) # An array indicating the new cards that you were dealt to replace the cards that were not held. cards = hold['cards'] # The prize you won in credits. prize = hold['prize'] # This will be the server seed to the next game of video poker, so that you do not need to issue /videopoker/reseed after every game. server_seed_hash = hold['server_seed_hash']
def processCommand(self, retval): retval = retval.replace("\n", "") retval = retval.replace("\r", "") retval = retval.strip() if retval == "": return self.addCommandHistory(retval) # Macro-style substitutions here: if len(retval)>= 1 and retval[0] == ".": if len(retval) >= 2: if retval[1].isalpha(): retval = "self" + retval else: retval = "self" + retval # Now process the command, case-like: if retval == "run": self.inform("Running in thread...") self.engine.pleaseRun() # pass in callback, or not # self.engine.pleaseRun(self.redraw) # pass in callback elif retval == "runtillquit": self.done = 0 self.engine.pleaseRun() while not self.done: pass return 1 elif retval == "step": self.stepEngine() elif retval == "info": print "-------------------------------------------------------------" print "Brain file:\t%s" % self.engine.brainfile print "Brain:\t\t%s" % self.engine.brain print "Robot:\t\t%s" % self.engine.robot print "World:\t\t%s" % self.engine.worldfile print "-------------------------------------------------------------" elif retval == "help": help() elif retval == "usage": usage() elif retval == "update": if self.engine.robot != 0: self.engine.robot.update() self.inform("Done!") else: self.inform("Define a robot first!") elif len(retval) >= 2 and retval[0:2] == "$$": os.system(retval[2:]) elif len(retval) >= 1 and retval[0] == "$": pipe = popen(retval[1:]) for line in pipe.readlines(): print line.strip() pipe.close() elif len(retval) >= 1 and retval[0] == "!": if retval == "!": self.listCommandHistory() elif retval == "!!": self.processCommand(self.history[-2]) # -1 is !! elif "-" in retval: start, stop = retval[1:].split("-") start, stop = start.strip(), stop.strip() if start == "": # neg number self.processCommand(self.history[-int(stop) - 1]) else: for i in range(int(start), int(stop) + 1): self.processCommand(self.history[i - 1]) else: val = retval[1:] if val.strip().isdigit(): self.processCommand(self.history[int(val) - 1]) else: self.listCommandHistory(val) elif retval == "about": about() elif retval == "reload": self.engine.reset() elif retval == "load robot": self.loadRobot() elif retval == "load brain": self.loadBrain() elif retval == "load simulator" or retval == "load server": print "Enter simulator or server (e.g., StageSimulator, PlayerServer)" self.loadSim() elif retval == "stop": self.engine.pleaseStop() self.inform("Stopped!") elif retval == "quit" or retval == "exit" or retval == "bye": self.done = 1 return 1 elif retval == "edit": if self.engine.brainfile != '': if os.getenv("EDITOR"): editor = os.getenv("EDITOR") else: editor = "emacs" os.system("%s %s" % (editor, self.engine.brainfile)) self.inform("Reloading...") self.engine.reset() else: self.inform("Need to load a brain first!") elif retval[:8] == "unwatch ": self.watcher.unwatch(retval[7:].strip()) elif retval[:5] == "view ": self.objectBrowser(retval[5:]) elif retval[:6] == "watch ": self._populateEnv() self.watch(retval[5:].strip()) elif retval[:7] == "browse ": self.objectBrowser(retval[7:].strip()) else: # elif len(retval) > 0 and retval[0] == "!": exp1 = """_retval = """ + string.strip(retval) _retval = "error" exp2 = string.strip(retval) # perhaps could do these once, but could change: self._populateEnv() print ">>> ", print retval try: _retval = eval(exp2, self.environment) except: try: exec exp1 in self.environment except: try: exec exp2 in self.environment except: print self.formatExceptionInfo() else: print "Ok" else: print "Ok" else: if _retval != None: print _retval self.updateDeviceList() return 0
def makestatus(name, thisuser): pipe = posix.popen('lpq -P' + name + ' 2>&1', 'r') lines = [] users = {} aheadbytes = 0 aheadjobs = 0 userseen = 0 totalbytes = 0 totaljobs = 0 while 1: line = pipe.readline() if not line: break fields = string.split(line) n = len(fields) if len(fields) >= 6 and fields[n-1] == 'bytes': rank = fields[0] user = fields[1] job = fields[2] files = fields[3:-2] bytes = eval(fields[n-2]) if user == thisuser: userseen = 1 elif not userseen: aheadbytes = aheadbytes + bytes aheadjobs = aheadjobs + 1 totalbytes = totalbytes + bytes totaljobs = totaljobs + 1 if users.has_key(user): ujobs, ubytes = users[user] else: ujobs, ubytes = 0, 0 ujobs = ujobs + 1 ubytes = ubytes + bytes users[user] = ujobs, ubytes else: if fields and fields[0] <> 'Rank': line = string.strip(line) if line == 'no entries': line = name + ': idle' elif line[-22:] == ' is ready and printing': line = name lines.append(line) # if totaljobs: line = '%d K' % ((totalbytes+1023)/1024) if totaljobs <> len(users): line = line + ' (%d jobs)' % totaljobs if len(users) == 1: line = line + ' for %s' % (users.keys()[0],) else: line = line + ' for %d users' % len(users) if userseen: if aheadjobs == 0: line = line + ' (%s first)' % thisuser else: line = line + ' (%d K before %s)' % ( (aheadbytes+1023)/1024, thisuser) lines.append(line) # sts = pipe.close() if sts: lines.append('lpq exit status %r' % (sts,)) return string.joinfields(lines, ': ')
def run_output(cmd): p = posix.popen(cmd) lines = [ l.rstrip() for l in p.readlines() ] p.close() return lines