This question already has an answer here:
windows batch script not execute next line after "adb shell"
(1 answer)
Closed 5 years ago.
I have a .bat file that runs script for testing an app and printing the log to file i have all the commands i tested them manually.
Problem:
after entering the command adb shell, the shell opens in the command prompt. I wrote the next commands that are entered in the shell with root#generic
the commands aren't going through and it just waits at that spot.
what do i have to type in front of the commands to make them appear
example of what i have
cd directory of sdk
adb
adb shell
am instrumentation ... (this is the command that won't go through once the shell is open.
any help appreciated I've tried a few things with no success
Just use the following line in your batch file:
adb shell am instrumentation
that will connect to the shell on the Android device and run the am command.
Related
This question already has answers here:
set up device for development (???????????? no permissions)
(30 answers)
Closed 4 years ago.
On Ubuntu Android Studio shows devices as null.
Every time I turn on my laptop, I need to run the following console commands to add permissions:
./adb devices
./adb kill-server
sudo ./adb devices
Enter my password and then repeat:
./adb kill-server
./adb devices
Note I'm using a xiaomi phone.
Is there a way to get around this permission issues so I don't have to do it ever time.
Anyway, what I did to solve this problem.
Defined in what cases I need to run these commands. For most ubuntu users there is a home folder (hidden file .bashrc).
In which you can record the launch of these commands. But these commands will be triggered when you enter the bash command in the console.
Since I have a shell .zshrc then I did the following:
open console: gedit .zshrc
When the file opens, add the following line:
./.add_device_permissions.sh
After or before, we need to create this file: .add_device_permissions.sh in which we write the following:
#!/bin/bash
# Add permissions for Xiaomi Redmi Note 5
ADB="/home/vadimm/Android/Sdk/platform-tools/adb"
$ADB devices
$ADB kill-server
cat .permissions_redmi_note | sudo -S $ADB devices
$ADB kill-server
cat .permissions_redmi_note | sudo -S $ADB devices
Also we need create .permissions_redmi_note where we need to hardcode our password.
Not to add to the file .zshrc unnecessary we can specify the path when starting the system itself: Startup Applications Preferences
Where we press on "Add" and write our command: /home/vadimm/.add_device_permissions.sh
This question already has answers here:
'adb' is not recognized as an internal or external command, operable program or batch file
(27 answers)
Closed 6 years ago.
For example, I want to execute this command from this tutorial:
$ adb shell monkey -p your.package.name -v 500
How do I do it? Where do I enter the command? I've tried entering it into the terminal but it says that '$' is not recognized.
I also tried removing '$' but it then says that "'adb' is not recognized as an internal or external command,
operable program or batch file."
$ isn't part of the command.
Use adb shell monkey -p your.package.name -v 500
adb is the command you ran on your terminal.
For example:
adb devices
shows you the connected devices.
adb shell
Starts a remote shell in the target emulator/device instance.
See https://developer.android.com/studio/command-line/adb.html for more info about adb.
I have one shell script placed in /sdcard/test.sh
And the test.sh file has the below command.
screenrecord --time-limit 10 /sdcard/sreee.mp4
When I run this command from adb shell command from Windows machine command executed successfully without any errors.
My Question is how can I execute the same script from Android app where When I press the start button?
Could you please help me out on this with a best example?
This question already has answers here:
Difference between sh and Bash
(11 answers)
Closed 1 year ago.
I'm trying to run linux shell script on adb shell. It's giving errors!
Here is the whole story:
I wrote a simple bash script hello.sh :
#!/bin/bash
function hello
{
echo "hello world!"
}
hello
running it as ./hello.sh produces the o/p
hello world!
Now I pushed the file to android device using
adb push hello.sh /data/folder_name
then ran following command to enter in adb shell
adb shell
In adb shell fired following commands
cd /data/folder_name
chmod 755 hello.sh
sh hello.sh
This is what I get on adb shell :
# sh hello.sh
sh hello.sh
function: not found
hello world!
hello: not found
#
What's happening here!
Or is there some different way to write function for adb shell script
I searched but didn't get proper solution
Please help.
Not sure about adb, but 'function' is not standard syntax. It is available in many shells, but the standard way to define a function is:
hello() { echo hello world; }
When invoked as sh, bash enters posix mode and it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well.
The reserved word function is optional for bash, but I think is unknown to historical versions of sh.
Try to invoke the command as
bash /tmp/test.sh
You don't need to push the script to your phone - simply expand it in the shell itself like so and you save yourself time:
adb shell "$hello.sh"
This question already has answers here:
adb shell su works but adb root does not
(11 answers)
Closed 5 years ago.
After rooting my device, I need to run adb root and then adb shell so I could then access my applications database. When trying to run adb root I keep getting "adbd cannot run as root in production builds". Why is this? The only other option is to use the Android emulator for testing, but we all know how terrible the emulator is (not really a viable development solution).
I finally found out how to do this! Basically you need to run adb shell first and then while you're in the shell run su, which will switch the shell to run as root!
$: adb shell
$: su
The one problem I still have is that sqlite3 is not installed so the command is not recognized.