How to Use Python to Execute Adb Commands

How to execute the adb commands in python scripts

This is pretty easy. Just use a loop!

for x in list:
os.system("adb install " + x)

That's it!

Also, for this to work, you need adb to be added to your PATH variable.
For information regarding how to do it, see here.

How to open adb shell and execute commands inside shell using python

Found a way to do it using communicate() method in subprocess module

procId = subprocess.Popen('adb shell', stdin = subprocess.PIPE)
procId.communicate('command1\ncommand2\nexit\n')

Using python to execute adb commands

cmd is a method of the Adb Python class, which allows you to execute commands on the previously selected device.

How to run two adb shell commands via Python, but store output of only one?

There is no reason for running both commands in the same shell session:

print subprocess.check_output(["adb", "shell", "du -sh /sdcard/qpython"])
subprocess.check_output(["adb", "shell", "rm -r /sdcard/qpython"])


Related Topics



Leave a reply



Submit