I chose to use the subprocess module when I implemented a wrapper for ADB in python. I found that the check_output(...) function came in handy because it would verify the command would return with a 0 status. If the command executed by check_output(...)
returns a non-zero status a CalledProcessError is thrown. I found this convenient as I could than report back to the user a specific ADB
command failed to run.
Here is a snippet of how I implemented the method. Feel free to reference my implementation of the ADB wrapper.
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)