Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,737,452 Members 42,178 Now Online
XDA Developers Android and Mobile Development Forum

adb shell and arrow keys

Tip us?
 
alapapa
Old
(Last edited by alapapa; 9th July 2009 at 06:05 PM.)
#1  
alapapa's Avatar
Senior Member - OP
Thanks Meter 7
Posts: 453
Join Date: Dec 2007
Angry adb shell and arrow keys

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?
I can help you become more human

 
Saiboogu
Old
(Last edited by Saiboogu; 9th July 2009 at 08:39 PM.)
#2  
Senior Member
Thanks Meter 5
Posts: 305
Join Date: Apr 2009
Location: 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.
 
alapapa
Old
#3  
alapapa's Avatar
Senior Member - OP
Thanks Meter 7
Posts: 453
Join Date: Dec 2007
Quote:
Originally Posted by Saiboogu View Post
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.
I can help you become more human

 
Darkstrumn
Old
#4  
Darkstrumn's Avatar
Junior Member
Thanks Meter 0
Posts: 28
Join Date: Sep 2007
Location: Phoenix
Post 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:
Select 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.
>>(Hack and the world hacks with you!
Wintermute:: G1-Black @ 245.75Mhz(cool) - 528Mhz(hot)
IPL:2.22.23.02 SPL:1.33.2005 RECOVERY:RA 1.7.0-Cyan
ROM:CM6 (Android/Debian)
SD::8/6: (4.65GB fat32|2.67GB ext3|250MB swap)
End of line. -(Darkstrumn:hacked.up)<<
 
alapapa
Old
#5  
alapapa's Avatar
Senior Member - OP
Thanks Meter 7
Posts: 453
Join Date: Dec 2007
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?
I can help you become more human

 
Darkstrumn
Old
#6  
Darkstrumn's Avatar
Junior Member
Thanks Meter 0
Posts: 28
Join Date: Sep 2007
Location: Phoenix
Quote:
Originally Posted by alapapa View Post
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.
>>(Hack and the world hacks with you!
Wintermute:: G1-Black @ 245.75Mhz(cool) - 528Mhz(hot)
IPL:2.22.23.02 SPL:1.33.2005 RECOVERY:RA 1.7.0-Cyan
ROM:CM6 (Android/Debian)
SD::8/6: (4.65GB fat32|2.67GB ext3|250MB swap)
End of line. -(Darkstrumn:hacked.up)<<
 
gdbjoe
Old
#7  
Junior Member
Thanks Meter 0
Posts: 27
Join Date: Oct 2009
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.
joe

Rooted T-Mobile G1 - CM 4.2.14.1
Recovery RA-dream-v1.5.2
SPL 1.33.2005 (aka DangerSPL)
Radio 2.22.19.26I
Class 6 8GB SD Card
Compcache off
Linux swp partition
setCPU
warning: dev in training
 
cboshuizen
Old
#8  
Junior Member
Thanks Meter 0
Posts: 10
Join Date: Mar 2008
In windows I created a .bat file called adb.bat, where c:/adb/ is where I installed the SDK:

Code:
Select 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
Old
#9  
Junior Member
Thanks Meter 0
Posts: 10
Join Date: Mar 2008
Default Putty on Windows

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

Code:
Select 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!

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


TRENDING IN THEMER...