Python Forum
adb commands - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: adb commands (/thread-29541.html)

Pages: 1 2


adb commands - Nickd12 - Sep-09-2020

So I'm trying to run adb commands in python on Macbook I'm basically trying to run amazons fireTv commands. I can run the commands in my Mac terminal however I can't seem to run them in python I've tried using subprocess, os.system and just about every other thing I can think of. Does anyone have any clue on how to do this?


RE: adb commands - bowlofred - Sep-09-2020

Please show one of your attempts, how you run the program, and all the output of the program (including any errors).

An example of how it works properly in the shell would be a good idea as well. You're probably close with the subprocess attempt.


RE: adb commands - Nickd12 - Sep-09-2020

with the Mac terminal once I'm connected all I have to do is just open it up and type 'adb shell input keyevent 85' basically a pauses or play for fireTv
import subprocess

useless_cat_call = subprocess.run(["cat"], stdout=subprocess.PIPE, text=True, input="adb shell input keyevent 85")
print(useless_cat_call.stdout)



RE: adb commands - bowlofred - Sep-09-2020

I don't know what you meaan by "once you're connected". Is the "adb..." command something you type in the shell?

If, so you want to run that, not "cat".

subprocess.run(["adb", "shell", "input", "keyevent", "85"])



RE: adb commands - Nickd12 - Sep-09-2020

forget the connected part I have to go through the process of connecting the ip of it but all I have to do is open terminal and type adb shell input keyevent 85. However I tried the command you gave me it said no such file or directory

FileNotFoundError: [Errno 2] No such file or directory: 'adb'


RE: adb commands - bowlofred - Sep-09-2020

What's your shell? If it's bash, what's the output of command -v adb?


RE: adb commands - Nickd12 - Sep-09-2020

Do I run it in Mac terminal? if so I got the path of adb '/Users/nickholasd/Library/Android/sdk/platform-tools/adb'

I ended up getting this to work thanks to your help 'subprocess.run(['/Users/nickholasd/Library/Android/sdk/platform-tools/adb', 'shell', 'input keyevent 85'])'
idk if this is the best way or there is any way to clean it up a little bit? either way thank you, you got me down the right path :)


RE: adb commands - Nickd12 - Sep-09-2020

one problem though is the command keeps wanting to run in the back ground its hard to explain once it does the command it will pause the tv but it won't move on to the next line of code any idea


RE: adb commands - bowlofred - Sep-09-2020

When you type the command in the terminal, do you get a prompt back immediately, or does it wait for you to type something else?


RE: adb commands - Nickd12 - Sep-09-2020

ah wait I do apologize it was not moving because of a different part of my program not because of the subprocess. Still I have one more question say I have a couple of commands I want to play, pause, menu or home they are all the same command essentially they just end in a different number like play is 'input keyevent 85' but home menu is 'input keyevent 1' instead of running the whole subprocess command line is there away where I could run 1 subprocess command line and just pull a specific command from a list and input it in the subprocess.