#NEWLINE# def adb_background_shell( device , command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , as_root = False ) : #NEWLINE# #INDENT# 'Runs the sepcified command in a subprocess, returning the the Popen object.' #NEWLINE# _check_env ( ) #NEWLINE# if as_root : #NEWLINE# #INDENT# command = "echo '{}' | su" . format ( escape_single_quotes ( command ) ) #NEWLINE# #UNINDENT# device_string = ( '-s {}' . format ( device ) if device else '' ) #NEWLINE# full_command = 'adb {} shell "{}"' . format ( device_string , escape_double_quotes ( command ) ) #NEWLINE# logger . debug ( full_command ) #NEWLINE# return subprocess . Popen ( full_command , stdout = stdout , stderr = stderr , shell = True )