Source

# XXX This should throw an exception if it is unusablefromsubprocessimportPopen,PIPEfromsysimportstderrdefreadsystem(cmd,cwd=None):ifnotcwd:cwd=Nonep=Popen(cmd,shell=False,stdout=PIPE,stderr=PIPE,cwd=cwd)lines=[]lastnl=Falseforlineinp.stdout:lastnl=(line[-1]=='\n')lines.append((line[:-1]iflastnlelseline).replace('\0','\n'))iflastnl:lines.append('')exit_code=p.poll()stderr.write(p.stderr.read())returnlines,exit_codedefreadlines(cmd,cwd=None):p=Popen(cmd,shell=False,stdout=PIPE,stderr=PIPE,cwd=cwd)p.stderr.close()forlineinp.stdout:yieldline[:-1]# vim: ft=python ts=4 sw=4 sts=4 et tw=100