-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.

2
  • docs.python.org/2/library/subprocess.html# Commented Jul 7, 2016 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. Commented Jul 8, 2016 at 0:46

1 Answer 1

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')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.