本文整理汇总了Python中popen2.Popen3方法的典型用法代码示例。如果您正苦于以下问题:Python popen2.Popen3方法的具体用法?Python popen2.Popen3怎么用?Python popen2.Popen3使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类popen2
的用法示例。
在下文中一共展示了popen2.Popen3方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print_chain
# 需要导入模块: import popen2 [as 别名]
# 或者: from popen2 import Popen3 [as 别名]
def print_chain(l):
llen = len(l) - 1
if llen < 0:
return ""
c = l[llen]
llen -= 1
s = "_ "
if not c.isSelfSigned():
s = "_ ... [Missing Root]\n"
else:
s += "%s [Self Signed]\n" % c.subject
i = 1
while (llen != -1):
c = l[llen]
s += "%s\_ %s" % (" "*i, c.subject)
if llen != 0:
s += "\n"
i += 2
llen -= 1
print s
# import popen2
# a=popen2.Popen3("openssl crl -text -inform DER -noout ", capturestderr=True)
# a.tochild.write(open("samples/klasa1.crl").read())
# a.tochild.close()
# a.poll()
示例2: readProcess
# 需要导入模块: import popen2 [as 别名]
# 或者: from popen2 import Popen3 [as 别名]
def readProcess(cmd, *args):
r"""Similar to `os.popen3`, but returns 2 strings (stdin, stdout) and the
exit code (unlike popen2, exit is 0 if no problems occured (for some
bizarre reason popen2 returns None... <sigh>).
FIXME: only works for UNIX; handling of signalled processes.
"""
import popen2
BUFSIZE=1024
import select
popen = popen2.Popen3((cmd,) + args, capturestderr=True)
which = {id(popen.fromchild): [],
id(popen.childerr): []}
select = Result(select.select)
read = Result(os.read)
try:
popen.tochild.close() # XXX make sure we're not waiting forever
while select([popen.fromchild, popen.childerr], [], []):
readSomething = False
for f in select.result[0]:
while read(f.fileno(), BUFSIZE):
which[id(f)].append(read.result)
readSomething = True
if not readSomething:
break
out, err = ["".join(which[id(f)])
for f in [popen.fromchild, popen.childerr]]
returncode = popen.wait()
if os.WIFEXITED(returncode):
exit = os.WEXITSTATUS(returncode)
else:
exit = returncode or 1 # HACK: ensure non-zero
finally:
try:
popen.fromchild.close()
finally:
popen.childerr.close()
return out or "", err or "", exit
示例3: __init__
# 需要导入模块: import popen2 [as 别名]
# 或者: from popen2 import Popen3 [as 别名]
def __init__(self, command, **kw):
if kw.get('stderr') == 'STDOUT':
popen2.Popen4.__init__(self, command, 1)
else:
popen2.Popen3.__init__(self, command, 1)
self.stdin = self.tochild
self.stdout = self.fromchild
self.stderr = self.childerr
示例4: wait
# 需要导入模块: import popen2 [as 别名]
# 或者: from popen2 import Popen3 [as 别名]
def wait(self, *args, **kw):
resultcode = popen2.Popen3.wait(self, *args, **kw)
if os.WIFEXITED(resultcode):
return os.WEXITSTATUS(resultcode)
elif os.WIFSIGNALED(resultcode):
return os.WTERMSIG(resultcode)
else:
return None
示例5: __init__
# 需要导入模块: import popen2 [as 别名]
# 或者: from popen2 import Popen3 [as 别名]
def __init__(self, command, **kw):
if kw.get('stderr') == 'STDOUT':
apply(popen2.Popen4.__init__, (self, command, 1))
else:
apply(popen2.Popen3.__init__, (self, command, 1))
self.stdin = self.tochild
self.stdout = self.fromchild
self.stderr = self.childerr
示例6: wait
# 需要导入模块: import popen2 [as 别名]
# 或者: from popen2 import Popen3 [as 别名]
def wait(self, *args, **kw):
resultcode = apply(popen2.Popen3.wait, (self,)+args, kw)
if os.WIFEXITED(resultcode):
return os.WEXITSTATUS(resultcode)
elif os.WIFSIGNALED(resultcode):
return os.WTERMSIG(resultcode)
else:
return None
示例7: decompress
# 需要导入模块: import popen2 [as 别名]
# 或者: from popen2 import Popen3 [as 别名]
def decompress(self, data):
pop = popen2.Popen3("bunzip2", capturestderr=1)
pop.tochild.write(data)
pop.tochild.close()
ret = pop.fromchild.read()
pop.fromchild.close()
if pop.wait() != 0:
ret = bz2.decompress(data)
return ret