Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shell/ batch scripting to direct commands to adb shell

I am trying to write a batch(for win) and a shell script for linux to automate key and touch events on a android UI. At the moment in a windows batch file I am starting a adb shell for each event for eg

    :again

adb shell am start -a android.intent.action.MAIN -n com.q.me.fui.activity/.InitActivity

sleep 15

adb shell sendevent /dev/input/event0 3 0 281
adb shell sendevent /dev/input/event0 3 1 70
adb shell sendevent /dev/input/event0 1 330 1
adb shell sendevent /dev/input/event0 0 0 0
adb shell sendevent /dev/input/event0 1 330 0
adb shell sendevent /dev/input/event0 0 0 0   
adb shell sendevent /dev/input/event0 1 330 1
adb shell sendevent /dev/input/event0 0 0 0
adb shell sendevent /dev/input/event0 1 330 0
adb shell sendevent /dev/input/event0 0 0 0
adb shell sendevent /dev/input/event0 0 0 0
adb shell sendevent /dev/input/event0 0 0 0   

sleep 5

adb shell input keyevent 82
adb shell input keyevent 20
adb shell input keyevent 20
adb shell input keyevent 22
adb shell input keyevent 22
adb shell input keyevent 22
adb shell input keyevent 66

sleep 5

goto again

The above code is infact starting a new adb shell each time. I want to avoid this. I want my batch script to start the adb shell only once and I would like to route the sendevent and other commands to the subshell, ie the adb shell.

Any idea how I can do this in win batch and Lin shell script?

like image 525
Harkish Avatar asked Aug 13 '10 06:08

Harkish


People also ask

How do I get to adb shell?

Open a command window in the folder by holding shift and right-clicking in an empty spot in the folder and selecting "Open command prompt/PowerShell here" in the menu. Then you can start using ADB — connect your phone and try .

How do I run a shell script from a batch file?

Open Command Prompt and go to the folder that contains your . sh file. Type Bash script-filename.sh and hit the enter key. It will execute the script, and depending on the file, you should see an output.

How do I run a batch file in adb shell?

Put adb shell > nameofyourtxt. txt. If the only command you want to execute is "su", you can do adb shell su.


1 Answers

Put all the commands you want to run at once in an external file, one per line, then run:

adb shell < commands.txt
like image 137
Drealmer Avatar answered Sep 17 '22 17:09

Drealmer