Dead simple question. My program runs for 12s, and then prints to stdout. When starting it with adb shell command, it does not even start...
$ adb shell
# /data/myprogram
CPU time: 12682.4 ms
$ adb shell /data/myprogram
<nothing>
$
My program runs for 12s, the log is a std::cout C++ print in stdout. I use adb-v1.0.32. My dev board runs android-5.0.2, with root access. When trying to execute it with adb shell, it returns to the prompt quickly. I checked if the program ran in background with busybox ps, it does not.
What am i missing?
Related
I am trying to access adb shell of an android device and pass multiple commands such as
adb root
adb shell
cd /data/local/tmp
export PATH =/data/local/tmp:$PATH
export PATH =/data/local/tmp/testcases:$PATH
sh ./runltp -p -l 1213reportipc.log -d /data/local/tmp/LTP13/tmp -f ipc1q
exit
While I am able to do this manually using adb shell, I am unable to do this via a Python script since as soon script execution encounters 'adb shell' command it spawns a new internal shell and rest of the commands are not executed.
Can anyone please help me with this.
Use a text editor such as sublime or something, write your full adb script using subprocess to send commands and run it while your laptop is connected to your phone and USB debugging is switched on.
import subprocess
subprocess.call("adb shell <your command here>", shell = True)
subprocess.call("adb shell tap 172 3241", shell = True) -- example
etc, just put your commands after the 'adb shell' and run the python script. This should type all your commands into the adb shell. You should even be able to enter commands such as
subprocess.call("adb kill-server", shell=True)
or subprocess.call("adb root", shell=True)
I need to take the native dump of the android process.
The cmd I am using is:
adb shell am dumpheap -n <pid> /data/local/tmp/dump.txt
The device is S8, Oreo OS.
Everytime I run this cmd, the 'dump.txt' is generated with the following content:
Native heap dump not available. To enable, run these commands
(requires root):$ adb shell setprop libc.debug.malloc 1 $ adb shell
stop $ adb shell start
Though I am doing it says and the phone is also rooted but it still gives the same content.
I am stuck. Any help would be appreciated.
I am trying to run a shell script in the background on an Android phone via ADB. To simplify let's make it sleep 100:
$ adb shell
$ echo "nohup sleep 100&" > /data/local/tmp/test.sh
$ sh /data/local/tmp/test.sh
(does not block and returns to the shell immediately as expected. However:)
$ exit
(blocks until the sleep process is done)
Doing the same thing through a single adb command line is blocking as well:
$ adb shell sh /data/local/tmp/test.sh
Does run the script correctly, but the adb call blocks until 'sleep 100' is done. The sleep process keeps running if I CTRL-C out of adb, so the nohup part seems to be working correctly.
How can I get adb to exit after spawning the subprocess without forcefully killing the adb process on the host side?
adb shell 'nohup sleep 10 2>/dev/null 1>/dev/null &' works as expected - starts the process and does not block.
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
I want to make it easier to access the sqlite databases on the emulator, so I've created a batch file that successfully runs the first line, but is there a way to run the second line from the batch file? (At this point adb is already running, so it would be running a command in the shell.)
adb -s emulator-5554 shell
# sqlite3 /data/data/com.myProject/databases/myDatabase
UPDATE:
For some reason
adb -s emulator-5554 shell sqlite3 /data/data/com.myProject/databases/myDatabase
prevents you from using the command line. Typing and pasting both seemed to be blocked. I ran this line in a command line outside of the batch and it does the same thing.
Separate lines work fine:
adb -s emulator-5554 shell
sqlite3 /data/data/com.myProject/databases/myDatabase
but this doesn't work in the batch file (the sqlite3 command gets executed too early).
You can run specific commands other than just an interactive shell on the target device. eg:
adb -s emulator-5554 shell ls /sdcard
or
adb -s emulator-5554 shell sqlite3 /data/data/com..../database.db
Once it gets complicated, it might be better to use a script that you copy over onto the device and run on demand.
You can use input redirection to send a stream of commands to ADB:
adb -s emulator-5554 shell <a.txt
Where a.txt contains
sqlite3 /data/data/com.myProject/databases/myDatabase
logout
This scales better. a.txt can grow as big as you want.