def _run_command(self, cmd):
"""
Execute an adb command via the subprocess module. If the process exits with
a exit status of zero, the output is encapsulated into a ADBCommandResult and
returned. Otherwise, an ADBExecutionError is thrown.
"""
try:
output = check_output(cmd, stderr=subprocess.STDOUT)
return ADBCommandResult(0,output)
except CalledProcessError as e:
raise ADBProcessError(e.cmd, e.returncode, e.output)
当我用python实现ADB的包装器时,我选择使用subprocess模块。我发现check_output(...)函数很方便,因为它可以验证命令返回的状态是否为0。如果
check_output(...)
执行的命令返回非零状态,则抛出CalledProcessError。我发现这很方便,因为我可以向用户报告一个特定的ADB
命令未能运行。在下面是我如何实现该方法的一个片段。请随意参考我的ADB wrapper实现。在
相关问题 更多 >
编程相关推荐