本文整理汇总了Python中resource.Popen.communicate方法的典型用法代码示例。如果您正苦于以下问题:Python Popen.communicate方法的具体用法?Python Popen.communicate怎么用?Python Popen.communicate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resource.Popen
的用法示例。
在下文中一共展示了Popen.communicate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: subcmd_voluuidget
# 需要导入模块: from resource import Popen [as 别名]
# 或者: from resource.Popen import communicate [as 别名]
def subcmd_voluuidget(args):
from subprocess import Popen, PIPE
import xml.etree.ElementTree as XET
ParseError = XET.ParseError if hasattr(XET, 'ParseError') else SyntaxError
cmd = ['gluster', '--xml', '--remote-host=' + args.host,
'volume', 'info', args.volname]
if args.inet6:
cmd.append("--inet6")
po = Popen(cmd, bufsize=0,
stdin=None, stdout=PIPE, stderr=PIPE,
universal_newlines=True)
vix, err = po.communicate()
if po.returncode != 0:
logging.info(lf("Volume info failed, unable to get "
"volume uuid of slavevol, "
"returning empty string",
slavevol=args.volname,
slavehost=args.host,
error=po.returncode))
return ""
vi = XET.fromstring(vix)
if vi.find('opRet').text != '0':
logging.info(lf("Unable to get volume uuid of slavevol, "
"returning empty string",
slavevol=args.volname,
slavehost=args.host,
error=vi.find('opErrstr').text))
return ""
try:
voluuid = vi.find("volInfo/volumes/volume/id").text
except (ParseError, AttributeError, ValueError) as e:
logging.info(lf("Parsing failed to volume uuid of slavevol, "
"returning empty string",
slavevol=args.volname,
slavehost=args.host,
error=e))
voluuid = ""
print(voluuid)