-1

I want to use ADB shell to access my device internal storage and then access information using Python. I know how to execute single adb command from Python using:

cmd1 = 'adb shell ls'
s1 = subprocess.check_output(cmd1.split())

Also I found out that we can use && or || or & or ; to combine multiple commands when we are using linux terminal to execute the commands here at link1 link2 link3.

But I cannot see(till now) how to use these and combine commands which one can use in Pyhton. For example I want to do something in Python which would give me the equivalent result of running these four commands in linux terminal.

adb devices
adb shell
cd /dev/block
find -name boot

So does anyone knows how I can execute this in Python.

Thanks.

Community
  • 1
  • 1
  • https://docs.python.org/2/library/subprocess.html# – miyamoto Jul 07 '16 at 22:57
  • @miyamoto Thanks. But for my particular case, it can be solved using `cmd1 = adb shell find /dev/block -name boot` and then `s1 = subprocess.check_output(cmd1.split())`. So here I can get the answer in one command itself. – Manmeet Khurana Jul 08 '16 at 00:46

1 Answers1

0

You can use communicate() method to do this

procId = subprocess.Popen('adb shell',stdin = subprocess.PIPE)
procId.communicate('cd /dev/block\nfind -name boot\n')
Ankur
  • 185
  • 1
  • 2
  • 10