adb shell and arrow keys

Search This thread

alapapa

Senior Member
Dec 18, 2007
456
8
is it just me, or when you "adb shell" into the device and then use a program that uses the arrow keys everything goes berserk?

it seems like it's overlaying the command history into the on-screen buffer and all future interactions are corrupted beyond repair.

for example, run vi and use arrow keys to navigate around (yes, i know there are other methods for this, just using this to illustrate) and it pulls info from some sort of history buffer on to the screen.

another example is the ash shell. up and down arrows behave nicely at first allowing you to scroll through your command history. but, it degrades fairly rapidly into being unusable

this does not seem to be an issue using scroll ball in terminal on the device.

I can't find anything in the Android Issues Page.

I've reproduced this in multiple builds on multiple OS's on multiple machines (but I've only got one G1, hence this thread)

Does anyone have any insight?
 
Last edited:

Saiboogu

Senior Member
Apr 28, 2009
305
5
Frostburg MD
What OS? Mine behaves this way too, and I think the root problem is the Windows command prompt. Read a comment somewhere on here that makes sense - something along the lines of cmd.exe not properly interpretting ANSI control codes? Need to hit up Google, maybe there's an alternative command shell that would solve this for Windows users.

EDIT: Ok, really need to work on reading comprehension - you tried multiple OSes? I was all set to blame MS. Anyway, I tested in Cygwin, Command2, Command2 wrapped around bash.exe .. No luck. Problem has to be in ADB itself somewhere, either the daemon on the phone or in all the clients.
 
Last edited:

alapapa

Senior Member
Dec 18, 2007
456
8
What OS? Mine behaves this way too, and I think the root problem is the Windows command prompt. Read a comment somewhere on here that makes sense - something along the lines of cmd.exe not properly interpretting ANSI control codes? Need to hit up Google, maybe there's an alternative command shell that would solve this for Windows users.

Thx for the reply.

I use a Mac mostly, but have similar response in Linux and Windows.

I've tried Terminal.app as well as iTerm on the Mac.
I tried cmd.exe, powershell, & cygwin / bash in Windows.

I agree it almost has to do have something to do with the way the adb daemon handles ANSI codes.
 

Darkstrumn

Member
Sep 5, 2007
28
0
Phoenix
Maybe this will help...

Hi All,

I don't reckon there isn't an actual problem.
The "DOS" console is not a terminal program and thus doesn't behave proper, and the DOS telnet program is just as bad!
In linux, the console is a terminal program, but is also very generic.

The adb shell is not a very good telnet server either in terms of terminal handling; which all really boils down to the sh being to limited as a login shell.

The following may help a little.

Have PuTTY or the like handy.
For windows, copy paste the following or something like it into a bat file (dlink.bat I called it):
The important bit is the forwarding...
Code:
@echo off
:init
::REM //-----------------------------------------------------------------------
set prog=%~f0&&REM This
set progDir=%~dp0&&REM This location
set workdir=%cd%&&REM Current locataion
set ADB=%progDir%adb
echo --Droid Link--
echo current settings:
echo -----------------
echo prog=%prog%
echo progDir=%progDir%
echo workdir=%workdir%
echo -----------------
::REM //-----------------------------------------------------------------------
::REM //ensure a clean house
%ADB% kill-server&&echo adb server clean: Ok.||echo adb server clean: Problem...
::REM //start fresh server instance, use its own shell as it will not detach from the shell until it ends elsewise due to it running in daemon mode
%SystemRoot%\system32\cmd.exe /e:on/v:on/f:on /c "%ADB% root>nul:"
::REM //get id of the Android (will need to be adjusted for more than one)
for /f %%a in ('"%ADB% devices|find "HT""') do set adev=%%a
::REM //see if we found our device
if .%adev%.==.. (
    echo Android not detected...
    goto :done
) else (
    echo Android detected as:%adev%
    )
::REM /if
set DROID=%ADB% -s %adev%
::REM //-----------------------------------------------------------------------
:begin
::REM //-----------------------------------------------------------------------
::REM //forward telnet port
%DROID% forward tcp:18023 tcp:23
::REM //forward ssh port
%DROID% forward tcp:18022 tcp:22
echo This terminal is now held by --Droid Link--
echo You can now connect to Android:%adev% via telnet host:127.0.0.1 port:18023
echo And if you start a ssh server...
echo You can connect to Android:%adev% via ssh host:127.0.0.1 port:18022
echo For best results, use a program like PuTTY or something (dos telnet is lacking).
%DROID% shell telnetd
echo --Droid Link: Closed---
::REM //-----------------------------------------------------------------------
:done
::REM //-----------------------------------------------------------------------
%ADB% kill-server&&echo adb server off-line.||echo adb server dropped: off-line.
::REM //cleanup
set DROID=
set ADB=
set adev=
::REM //-----------------------------------------------------------------------
:xit
echo End of line.
::REM //-----------------------------------------------------------------------
For Mac, I'm afraid I rely on my linux syntax and pray it works the same in OSX:
adb -s {device ID} forward tcp:18023 tcp:23
note the adb -d forward tcp:18023 tcp:23 may do the trick also.

I use PuTTY and have a profile called Android-Telnet, which can be called from the console as putty.exe -load Android-Telnet

PuTTY may or may not be the end-all, be-all of terminal programs, but I like it, it works, and is multiplatform.:)

Hope that helps.
 

alapapa

Senior Member
Dec 18, 2007
456
8
tyvm, Darkstrumn. that worked great! Can't believe i didn't think to try this as a workaround.

all i did (on OSX Leopard):

adb shell telnetd &
adb forward tcp:9999 tcp:23
telnet localhost 9999

now, to get working on compiling dropbear 0.52 and / or patching adb *eek*

i guess a related question becomes, is there any way to change ash to the default login shell?
 

Darkstrumn

Member
Sep 5, 2007
28
0
Phoenix
tyvm, Darkstrumn. that worked great! Can't believe i didn't think to try this as a workaround.

all i did (on OSX Leopard):

adb shell telnetd &
adb forward tcp:9999 tcp:23
telnet localhost 9999

now, to get working on compiling dropbear 0.52 and / or patching adb *eek*

i guess a related question becomes, is there any way to change ash to the default login shell?

Just a note: The windows version of this is just as simple as those 3 commands, the complexity of the script is simply allowing the script to lock-on to the device by id; my actual scripts enumerate the devices including the emulator into the %adevN% variables where N is 0-X. %adev0% will always be the first instance of the emulator found and %adev1% will always be the first instance of a true device found. I simple made it light and posted it. I think it only matters if you are using the emulator and have a live device connected and what to work with both.

Let me know if the enumeration script would be handy and I can post it also.:)

I haven't gone the route of dropbear just yet, but I'm interested in using ssh vs telnet.

As far as ash goes, I reckon the trick is to setup a chroot to use it as the console...maybe override the console service defined in init.rc.

Note I think ash is expecting the passwd file to exist and have meaning, so that may need to be setup to have ash behave a little better in the Android environment.
 

gdbjoe

Member
Oct 9, 2009
27
0
Thanks! This worked a treat for me.

I was having trouble with lynx and ansi chars within an adb session, the forward made my day :).

Actually I got rid of the complex batch above, I just set up two small batch files:

myadbshell1.bat
@echo 1
@adb forward tcp:18022 tcp:22
@adb forward tcp:18023 tcp:23
@adb shell telnetd
@exit

myadbshell2.bat
@echo 2
@putty.exe telnet://127.0.0.1:18023
@exit

Run the first, then the second.
Do your story in putty, when exit everything will close.
Why echo 1 and 2? Because withouy I was getting the two batchs hanging, dunno why. :-?

Everything on windows environment.
 

cboshuizen

Member
Mar 9, 2008
10
0
In windows I created a .bat file called adb.bat, where c:/adb/ is where I installed the SDK:

Code:
c:/adb/tools/adb remount
c:/adb/tools/adb forward tcp:9999 tcp:23
c:/adb/tools/adb shell telnetd

I run this file as Administrator, and then I can telnet into localhost:9999 with putty. Works great!
 

cboshuizen

Member
Mar 9, 2008
10
0
Putty on Windows

In windows I created a .bat file called adb.bat, where c:/adb/ is where I installed the SDK:

Code:
c:/adb/tools/adb remount
c:/adb/tools/adb forward tcp:9999 tcp:23
c:/adb/tools/adb shell telnetd

I run this file as Administrator, and then I can telnet into localhost:9999 with putty. Works great!