adb command in cmd file (windows) - android

I have command and she working fine in cmd in manual mode:
adb shell
su
echo 'AT+EGMR=1,7,"558378919678440"' > /dev/radio/pttycmd1
How do I run this command in a .bat file?
I tried such options, but they do not work:
adb shell su -с echo 'AT+EGMR=1,7,"558378919678440"' > /dev/radio/pttycmd1
adb shell "su -с 'echo 'AT+EGMR=1,7,"558378919678440"' > /dev/radio/pttycmd1'"
adb shell su "-с echo 'AT+EGMR=1,7,"558378919678440"' > /dev/radio/pttycmd1"
Please help.

Using bash you can run this command
adb shell su root sh -c $'"echo \'AT+EGMR=1,7,\\"558378919678440\\"\' > /dev/radio/pttycmd1"'
So, if you are running it from a batch file you may need to invoke bash first

Related

Batch script for adb commands [duplicate]

This question already has answers here:
How to use su command over adb shell?
(7 answers)
Running ADB commands through powershell
(1 answer)
Closed 6 years ago.
i am writing batch script for executing adb commands but while executing "SU" commands only the first commands runs "adb shell" and stops
as the script is typing all the commands very fast and not waiting for previous command to run completely so that next command can be entered into the shell window that is "su" example of code is below
:lckscreen
adb shell
su
rm /data/system/gesture.key
rm /data/system/*.key
exit
exit
pause
goto menu4
i also tried
adb shell & su
but still same Result
shell#Samsung_s4:/ $
please help
Please try
adb shell "su -c 'rm /data/system/gesture.key'"
adb shell "su -c 'rm /data/system/*.key'"
and see the question in How to use su command over adb shell?
You will have to create a separate .txt file containing all the shell commands, in example:
su
mount -o remount,rw /system
mv /system/build.prop /sdcard
Make sure to have put an "enter" at the bottom to execute the last command. Now, in the bat file, where you'd normally put adb shell etc. Put adb shell > nameofyourtxt.txt.
If the only command you want to execute is "su", you can do adb shell su.

How to start daemon on android by adb

Can you help me please, my head is swollen...
I am trying to run daemon on android emu/device by command:
adb -s <device_name> shell su -c /dir/daemon <port_number>
but nothink happens, and no errors!
If I do:
adb -s <device> shell
and then form shell cmdline:
su -c /dir/daemon <port_number>
than its work fine. I try use shell-script and run:
adb -s <device_name> shell sh su -c /dir/script.sh <port_number>
and I even try to generate script from Qt code with port number and use:
adb -s <device_name> shell sh su -c /dir/script.sh
but its not helped... problem that if I enter to adb shell previous to run daemon - its work. Another problem is on different device/emu/iso_image different command format could not work. For example:
adb -s <device_name> shell su -c /dir/daemon <port_number> // work at emu, but not at iso
and vice:
adb -s <device_name> shell su -c "/dir/daemon <port_number>" // work at iso
etc.
Everybody can answer what's the matter?
Sorry for my english
adb shell su -c "/dir > /dev/null 2> /dev/null < /dev/null &"
or
shell su -c /data/local/tmp/start_daemon.sh
#!/system/bin/sh
/data/local/tmp/nohup
/data/local/tmp/daemon <portn_number> &

Enter adb shell from python

I'm trying to execute command to adb shell from python
I'm using Windows OS
On CMD :
C:\Users\deounix>adb shell
shell#android:/ $ su root
su root
root#android:/ # reboot
What I'm doing is :
import os
os.popen("adb shell & su root & reboot")
But it isn't work
How can I do it?
import os
os.system("adb shell su -c reboot")
import os
os.system("c:/platform-tools/adb devices")
To run any command like adb devices on python execute the above command
This will work definitely. You just need to confirm the path where you have got the adb shell

How to use su command over adb shell?

I need to make a script that executes a lots of thing on Android device, my device is rooted, when I enter on the shell, I can give the command su, and it works but I need pass this command like:
adb shell "
su;
mv /sdcard/Download/app_test /data/local;
cd /data/local;
./app_test;
exit;
exit;
"
when I put some commands before the su it works, according what I read su creates a new shell that return immediately, but I need give commands on the su shell, how can I do that?
Well, if your phone is rooted you can run commands with the su -c command.
Here is an example of a cat command on the build.prop file to get a phone's product information.
adb shell "su -c 'cat /system/build.prop |grep "product"'"
This invokes root permission and runs the command inside the ' '.
Notice the 5 end quotes, that is required that you close ALL your end quotes or you will get an error.
For clarification the format is like this.
adb shell "su -c '[your command goes here]'"
Make sure you enter the command EXACTLY the way that you normally would when running it in shell.
On my Linux, I see an error with
adb shell "su -c '[your command goes here]'"
su: invalid uid/gid '-c'
The solution is on Linux
adb shell su 0 '[your command goes here]'
The su command does not execute anything, it just raise your privileges.
Try adb shell su -c YOUR_COMMAND.
By default CM10 only allows root access from Apps not ADB. Go to Settings -> Developer options -> Root access, and change option to "Apps and ADB".
1. adb shell su
win cmd
C:\>adb shell id
uid=2000(shell) gid=2000(shell)
C:\>adb shell 'su -c id'
/system/bin/sh: su -c id: inaccessible or not found
C:\>adb shell "su -c id"
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
C:\>adb shell su -c id
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
win msys bash
msys2#bash:~$ adb shell 'su -c id'
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
msys2#bash:~$ adb shell "su -c id"
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
msys2#bash:~$ adb shell su -c id
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
2. adb shell -t
if want run am cmd, -t option maybe required:
C:\>adb shell su -c am stack list
cmd: Failure calling service activity: Failed transaction (2147483646)
C:\>adb shell -t su -c am stack list
Stack id=0 bounds=[0,0][1200,1920] displayId=0 userId=0
...
shell options:
shell [-e ESCAPE] [-n] [-Tt] [-x] [COMMAND...]
run remote shell command (interactive shell if no command given)
-e: choose escape character, or "none"; default '~'
-n: don't read from stdin
-T: disable pty allocation
-t: allocate a pty if on a tty (-tt: force pty allocation)
-x: disable remote exit codes and stdout/stderr separation
Android Debug Bridge version 1.0.41
Version 30.0.5-6877874
for my use case, i wanted to grab the SHA1 hash from the magisk config file. the below worked for me.
adb shell "su -c "cat /sbin/.magisk/config | grep SHA | awk -F= '{ print $2 }'""
I opt for the following:
adb shell su root <your command>
e.g., to access the external storage (sd card):
adb shell su root ls storage/0/emulated

bash passing arguments invalid (adb)

sorry for my English.
I write bash-file, that uses variable: shared_var=/system/xbin
My script-file:
exec="./adb shell chmod 644 $shared_var/$2"
echo $exec
$exec
Let's run this script:
>bash gapp.sh misc su
./adb shell chmod 644 /system/xbin/su
: No such file or directory n/su
Let's run string "./adb shell chmod 644 /system/xbin/su" without script:
> ./adb shell chmod 644 /system/xbin/su
(No output, OK)
I have few questions:
Why are script and direct input in terminal have different results?
Why instead of "No such file or directory /system/xbin/su" adb returns "No soch file or directoryn/su" (adb result looks distorted)
What is solution of my problem?
does it work, if your shell script only has
echo ./adb shell chmod 644 $shared_var/$2
./adb shell chmod 644 $shared_var/$2
ie, not assigning it to another variable, and no quoted strings
Also, if you are editing the file in Windows, make sure you save the file with Unix linefeeds.

Categories

Resources