Search code examples
androidpythonadb

Running multiple adb commands with python Popen or os.system


One problem with ADB is that you need multiple commands to get things done. For example:

adb shell

su 

cp /data/local/x /data/local/y

exit

adb pull /data/local/y

Can this be done using python popen and os-system? Tried the example below without success..

print 'Starting emulator...'
subprocess.Popen(['emulator', '-avd', 'testavd'])
os.system('adb wait-for-device')
os.system('Perform whatever adb commands you need')

Any pointers?


Solution

  • You can simply do:

    adb shell su -c cp /data/local/x /data/local/y
    adb pull /data/local/y
    

    or, if you want to run more than one command (only Linux & OSX):

    adb shell <<EOF
    ls
    date
    cat /proc/version
    exit
    EOF