How to run a shell script in android app? - android

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?

Related

Android Shell locksettings command from device terminal

Since Oreo there is this fancy locksettings command, that allows you to change the screenlock from adb shell. Now, if I try to run it on my PC everything is working. On my handheld the command will just get an "Aborted." back. Why is that and how can I run the locksettings command from my device?
here is the code for the locksettings command, maybe you can already tell by that:
# Script to start "locksettings" on the device
#
base=/system
export CLASSPATH=$base/framework/locksettings.jar
exec app_process $base/bin com.android.commands.locksettings.LockSettingsCmd "$#"
Download QUTE, a command panel. Start from the first command click and run it. About 10 to 15 commands ran will give enough control over the system. Only because most of the commands are going to fail, unable to run. Then the terminal will suggest you to STACK, for the command code to lock setting. Copy the code and paste it in the terminal. For there your settings should be locked.

nohangup using ADB shell

I am trying to do a logcat to a file using adb shell by following command -
adb shell "nohup logcat -f /storage/sdcard0/myLog.txt -v time &"
If I do a ps | grep logcat, I don't see the logcat command. Even I tried to see nohup command, but it is not there. So somehow above command does not work.
However if I perform the command in 2 steps it works fine -
adb shell
nohup logcat -f /storage/sdcard0/myLog.txt -v time &
I can see the process using ps and logcat continues to record to the file even if I disconnect adb shell. Now I would like the first command to work, since I am using python scripts to issue commands via ADB. It is possible to change the python scripts, however I would like to know if I am doing anything wrong in issuing the first command and if it is possible to make it work.
try
adb logcat
not
adb shell logcat

adb shell command from batch file [duplicate]

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.

Running a shell script in Android from the Host

I have a Host development PC running Ubuntu and I am doing all the android development on it.From this PC I wanted to (adb) push some files(executables) to android filesystem (say /data/dir1) , cd into it and run that executable.Using a shell script (shown below) I can do this from the PC upto to connecting the android device and doing adb shell but I can not run other commands after that .
e.g scripts
adb push <file1> /data/dir1/
adb shell
cd data/dir1
./file1
I can run upto adb shell but not beyond that.How can I achieve the remaining two commands ( changing the directory to data/dir1 and running the ./file1) from the shell script running on the Host PC.
You
don't need to enter into the adb shell
, change the path and more.
You can accomplish everything in a single command , like
adb push my_script_file.sh /data/dir1/
adb shell sh data/dir1/my_script_file.sh
1.first of all go the root by the command sudo -i
write the program
adb shell ls data/dir1
3.execute it -./file
by the above program you can move to the folder in the shell

Start a process in background from adb shell without attaching the process to the terminal in Android

I have a simple problem.
I want to start/run a program file on an android phone using adb shell.
My Program is in /system/bin folder and has root privileges.
I want to run this program from my command prompt as adb shell runme 3000000 > logs.txt but it should not block the terminal, It should run in background.
I cannot use screen/disown/nohup for my problem as android doesn't have all this.
I tried
adb shell "runme >logs.txt &" but of no use.
When i issue command as
adb shell
# runme 3000000 > logs.txt &
It runs fine, when i exit the terminal/disconnect the device and then connect again to system.
Do adb shell ps | grep runme shows the process is still runnning in background.
Thanks
Busybox has nohup applet which works just fine in Android

Categories

Resources