I have a question regarding ADB.
I'm sorry about the title of this question as I really don't know how to put a good title to this.
I'm working with many android devices at the moment, and I noticed that on some devices, the following problem occurs.
Say I want to run a shell script (my_script.sh) that is located in the /data/local/tmp/ folder of the phone.
If I do this:
adb shell 'sh /data/local/tmp/my_script.sh &'
nothing happens on the phone.
If I just go into adb shell (by entering adb shell on a terminal) and when I get this prompt:
shell#android:/ $
and then I type in the following:
sh /data/local/tmp/my_script.sh &
everything works just fine.
This happens on only a few of the devices I have. So I'm not able to figure out what exactly I'm doing wrong.
Here is another piece of information that might help someone. If I don't use the "&" at the end (which means I don't run the script in a background process), everything works as well.
The following code gives the correct behavior:
adb shell 'sh /data/local/tmp/my_script.sh'
I'm completely lost, and I'm hoping someone here can help me out.
Thanks in advance!
UPDATE: So this issue has puzzled me for a while, and I spent quite a bit of time investigating this issue. I've noticed another behavior, say I lock the screen (by pressing the power key) and then issue the command:
adb shell 'sh /data/local/tmp/my_script.sh &'
And then unlock the screen, the script will run fine.
This is really the weirdest thing I've encountered in a long time.
I really hope someone can lend a hand here.
I guess you want to daemonize some program to run in the background. But normally the child process will got killed while the parent is gone. In this case, your adb shell is the parent process.
And this behavior is really different from device to device. I just tried it on my phone and found that "&" didn't take any effect, the shell command is still blocked.
I think a better way to handle it is to use standard daemonize approach of linux. Please refer to:
Write a daemonize native program
How to daemonize a script on a generic linux os
Related
So I think I did something wrong. At first everything was working alright. I was able to see my device when using adb devices and process shell commands. The problem began when I was trying out a faster way to flash my systemimage. I came across a website that had just what I needed. At first I was building my systemimage everytime, but overtime it became too long for minor corrections. So I tried syncing via adb. The commands I was using were adb remount adb shell stop adb sync and adb shell start in that order. One time I forgot to use the adb shell start and from that point on I cannot see my device under adb devices.
My question is could not running adb shell start after stopping it, really break the system that much. Or am I looking for the problem in the wrong place.
Also worth mentioning I am still able to flash systemimages via bootloader so I don't think the problem is usb related.
Well I fixed it. I don't if shell commands were the problem, but flashing everything (not only systemimage) seemed to fix the problem.
I've got a partially rooted android device. By partial root, I mean that I can only run root commands through ADB. I've figured out how to run these commands locally from within a terminal emulator on the device itself. My question is, how would I go about writing the code for an Android application that executes an ADB command (or multiple commands) from a button press? I can't find anything that explains how to run direct ADB commands through an app interface. Just to clarify, anything that involves "su" will not work on this device. It only accepts ADB input for root access.
Not sure if it works on Android, but have you tried this:
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("adb do something as root");
If you provide more info about what exactly you need to use adb for in this manner, there may be a better workaround. It is very unlikely you actually need this behavior in app, and I believe it would be generally frowned upon. It sounds like you want your app to have root, but this seems like a very unportable and unnecessary approach.
I want to use vi when running adb shell. Starting "vi" is easy. However, I found that the ESC key doesn't seem to get through to it, so I can't exit insert mode.
More broadly, it doesn't appear that I'm able to send an ESC character to the adb shell at all. I've scanned the web pretty thoroughly and haven't been able to find anyone with a similar problem (much less an answer).
I'm running VRUFNK1 on a Samsung S4. On the PC end I'm running the "adb shell" command from Cygwin under Windows.
Ideas???
UPDATE: Here's are some possible clues.
The adb shell doesn't seem to be the problem. I can capture ESC in a file running
od -cb > file, so ESC seems to be getting to the program being run under the adb shell.
All commands get echoed in my "adb shell" (as if set -v was on, but it isn't).
I notice that input doesn't seem to get sent to adb shell from my cygwin shell in "raw mode" -- i.e., any text I type gets buffered locally until I hit carriage return -- then the entire line gets sent. I'm not sure why that would make ESC ineffective, but certainly vi doesn't expect to be receiving input in quite that manner and perhaps its an indication of something unusual in my environment.
Similar to #1, bash (Bash X) seems to receive it, although echoing from bash is very strange. I can use ESC to enter "edit mode" in my bash shell (Bash X) to scroll through my history (I've run set -o vi), but the experience is very strange. When I hit ESC,k, nothing changes on the screen but my location in the command history goes up one rung (as it should); subsequent presses of 'k' cause a 'k' to be echoed to the screen (instead of the relevant command from my history list). When I finally hit carriage return, the correct command from my history list is executed (!).
UPDATE 2: Progress…
I tried setting the stty value in the "adb shell" to the same as the ones in my cygwin bash shell and that didn't have any effect.
I also tried this: Avoiding escape timeout issues in vim but it didn't help.
I tried this (by reading in from a file using :so <filename>).
Unfortunately, the commands weren't recognized by "vi" (they are actually "vim" commands).
Partial Solution:
Typing a <cr> immediately after the ESC when in "vi" works -- the ESC is accepted and I can exit the editor. It's awkward, and the editing window is still unusable (as if TERM was set to the wrong value), but this is progress.
Also, things work fine when I ssh in. That shell gets started by the telnet server; similar situation as Terminal Emulator directly on the device. Ssh has its own server which then forks off the shell. In the case of the "adb shell", the shell is forked off by /sbin/adbd -- as far as I can tell, there is simply something unusual about that environment. This is a huge step for me -- at least now I have a way to do full screen editing on the device using my PC (rather than editing directly on the S4's tiny screen). Thanks to Jack Palevich for that suggestion.
I can only think of two things to try at this point:
Try running adb shell against someone's device (but the device must be running root, so that I can run Busybox's "vi") (BTW, the version of "vi" is not the problem -- it runs fine from ssh.)
As someone else to run "vi" in "adb shell" on my device, from their host (preferably someone who has succeeded in running "adb shell" and vi somewhere previously.
I'm starting to think that It Simply Doesn't Work.
UPDATE 3: Info from XDA Developers
I found some relevant posts on the XDA Developers forum. It seems to be the case that people have had problems with this for a long time (since at least 2010). I didn't find any solutions.
XDA Link 1
XDA Link 2
XDA Link 3
There is also a paragraph listing various perceived/proposed adb shell bugs that match my experience, here:
Proposed ADB Shell Bugs
You're right - it simply doesn't work under Windows or Cygwin shell. I found that the simplest way to make it work is to use PuTTYTray.
Check my answer in the linked thread for instructions and additional details.
Another solution: Use Windows PowerShell instead of cygwin. Commands like 'o', 'esc', and ':wq' work nicely here.
I have many questions about Android command. I do not know where I should start But, anyway, I have put all question related Android commands. Here ;
Is subset of Linux commands come in Android by default ? Or, Are we installing something ?
In system/bin, there are lots of commands. Where can I find their meaning ? I have tried man, but man is not built in.
Can I start and stop application via start and stop command ?
Why cannot I run the reboot from terminal emulator ? The error permission is denied.
NOTE : feel free to reedit the question, if you see meaningless part.
Is subset of Linux commands come in Android by default ? Or, Are we installing something ?
A subset exists by default within the system. Things like ls, cd, mkdir, cat etc... are present. You can gain access to a wider range by installing Busy Box on a rooted device, as stated by Zac.
In system/bin, there are lots of commands. Where can I find their meaning ? I have tried man, but man is not built in.
The ADB Page is a good place to start. That covers many of the basic ADB and shell commands. It states near the bottom:
"For a complete list of commands and programs, start an emulator instance and use the adb -help command."
So you can use adb -help on an emualator or device to see a full list of the ADB and shell commands (note I think this list will be android specific commands only, it won't include things like cd,ls and other basic unix commands).
Can I start and stop application via start and stop command ?
No, it states on the ADB dev page:
start ........ Starts (restarts) an emulator/device instance.
stop ........ Stops execution of an emulator/device instance.
To start an application you'll use the am utility iirc it will look something like am start com.your.packagename It's been a while though, I might have syntax wrong. The instructions are listend if you issue the am command by itself with no params in a shell.
Why cannot I run the reboot from terminal emulator ? The error permission is denied.
The system prevents applications from rebooting the device unless they are signed with the same key as the OS. When you use the terminal emulator you are restricted to whatever permissions that application has declared. The reboot permission is not granted to any third party applications, so it won't work correctly from any terminals. You could probably do it if your device was rooted and you used su though
EDIT:
Here is another good resource that lists more of the shell commands
There are not many Linux commands included in android, however if you are rooted you can easily install busybox which has a large range of linux commands.
You need to have root access to reboot your device via the command line (to prevent any old app being able to do it)
this is my first time asking a question on stackoverflow.
I'm working on a small app on android just for fun over the school break. My app is working fine and displays logcat just fine when I am running it on emulator. But when everytime I try to run the app on my phone through debugging bridge, logcat never displays at all. I've tried every methods that I was able to find on google including:
going into ddms and selecting my device
using adb logcat -d foo:D *:S which only displays
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
etc
I remember it was working fine quite a while ago but since i have changed to my brand new computer it just don't work anymore. Please help :( im stuck here for like 3 hours now
thank you guys =)
Try some tricks below
Sometimes phone is not recognized by the driver. Run
sudo ./adb kill-server
sudo ./adb start-server
Update ddms, the latest ones are good, and there are fixes for many issues
Run ddms from command line, the one in eclipse is not as good as the command line one.
We cant exactly predict what may be the problem , but try these methods which may workout sometime.
*Use the command adb remount
*select the device within which select your application process
*Use the TAG for your logs and create new filter with that log name.
*Click between your filter and All messages in Log cat.
*Try re connecting the device again.
If still there is problem then please share more information.
I've just solved the issue by using Log.e instead of other log levels. This took me so long time to figure it out, i've reinstalled my eclipse and adb but it didn't help at all.
I don't know if this is just for me but i hope this helps for some of you who are having same trouble as me
use Log.e !!