Fixing ADB shell colors in the windows command prompt.


At some point this morning I was suddenly and without warning struck with the urge to get the old AALib demo “BB” running on my ‘droid. Eventually I had an ARM build of Debian running and BB installed without any fuss. (apt-get install bb).

What I hadn’t anticipated though was that using ADB shell from the windows command prompt would result in color code escape sequences being printed straight to the screen. Worse still, I couldn’t Ctrl+C out of a program without killing ADB shell, and other keys such as the arrows and escape key were being ignored completely.

So without further ado, here are a few solutions :

1 – Connecting to your Android using Cygwin.

Cygwin (windows)

Cygwin is a windows port and implementation of the POSIX environment and GNU toolchain and shell.(sh, grep, cat, find, etc). Setup is a fairly straight forward sort of affair. Download setup.exe from, hammer Enter ’till it’s done, and run c:\cygwin\cygwin.bat .

Now you can run ADB shell from the cygwin shell:

cd /cygdrive/c/androidsdkwindows/platformtools/
./adb shell | cat

If everything went to plan, you’ll just see another “$” ’till you start fiddling. You’d think that the cygwin shell could handle the color codes, but no. That’s why we pipe it into cat with the  | cat part.

Though this is about the easiest and quickest way to connect, it’s still not without issue. Most key combinations will work, but Ctrl+C will still close the ADB  shell itsself. It works, but if you can, I’d definitely recommend the second solution.

2 – Connecting to your Android via telnet/telnetd.

Putty – A free telnet client. (Windows)
BusyBox – A free set of tools. (Android)

Firstly, to pull this method off, you’re going to need to root the phone and reboot. If for whatever reason you can’t or won’t root it, then by all means try, but you might not get too far.

Now grab and install Busybox from the Android Market. Busybox is a package containing the standard GNU toolchain binaries and a few others for good measure, but most importantly, it has the telnet deamon telnetd.

Open adb shell, and type the following:

busybox sh         #opens busybox’s shell.. more features.
su                           #don’t forget!
telnetd l sh >     #launch the telnet service/daemon


If everything went to plan, it should look a little something like this:

  1. [1]   Done                    telnetd l sh

You can close this terminal now, or exit, or whatever.
Now pop open putty in windows and enter the phone’s IP.
Select ‘telnet’ as the connection type (port 23) and hit Open.

Shell. Win.

This is probably about the best way to connect if you can. Once set up, telnetd will continue to run, allowing you to connect wirelessly just by opening Putty. Of course you can use a telnet client of your choice, but Putty handles the input/output side of things rather well.
When you’re ready to close the telnet daemon (as  you should eventually) just ‘kill -9 telnetd’. 


3 – Connect to the ‘droid using Linux. 

Plenty reasons to use it. Plenty not to.

For my purposes (messing around with a 14 year old ASCII art demo) it hardly seemed worthwhile, but installing a barebones linux distro in a virtual machine for example should only take 5 minutes.

In conclusion:

So how well did the demo run after all that? Really well!

While the ADB shell seemed initially to be more responsive, during the demo, Putty was the clear winner and was the only one not to start frame skipping.


Here are a few screenies:

(Note: It was clear the command prompt was going nowhere, so it got closed 30 or so seconds in.)


Leave a Reply

Your email address will not be published. Required fields are marked *