Take the 2-minute tour ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

When I adb shell into my device (from Windows desktop), and run some command there, sometimes I want to terminate that command. The standard unixy way to do it is with Ctrl+C key combination. However, when I do that, the whole adb shell terminates.

How can I terminate just the current program inside the shell, not the shell itself?

share|improve this question

6 Answers 6

up vote 9 down vote accepted

I found sort of a workaround for this (at least for a rooted phone). If a phone is rooted, busybox is most probably installed. stty is part of busybox.

stty intr ^x

Redefines Ctrl+X to act as a break command, e.g. what was previously Ctrl+C.

share|improve this answer
2  
That's pretty awesome. –  Matthew Read Jan 11 '12 at 5:36

Alt-NumPad 3 + Enter works for me. Alt-NumPad 0-NumPad 3 + Enter also works and displays "^C".

share|improve this answer

i was able to stop the top process and still stay in shell by typing the following in this order:

C

CTRL+Z

CTRL+M

if I did not type all 3 of those combos it would not stop and I would have to CTRL+C to exit the shell. I found this by just trying different combinations of keys and found it by accident. YMMV

share|improve this answer
    
Ctrl+Z suspends a process, e.g. you have to kill it later with kill or killall. This workaround is better than nothing, though... –  haimg Jan 11 '12 at 4:48
    
i realized that after when i did an "exit". funny thing, it wasnt the ctrl+z that did anything, it didnt actually go back to the shell until i did ctrl+m, and if i didnt type "c" first, it didnt do anything. –  Ryan Conrad Jan 11 '12 at 5:04
    
This doesn't work for me (I tried vmstat not top though). Interestingly, when I press Ctrl-Z it looks like nothing happens but in fact my input starts being redirected straight to the Windows shell and not to adb. adb's output (from vmstat) keeps showing up in the shell window but I could type cd C: (for example) and it would execute in the Windows shell. If I then pressed Ctrl-C the output would stop and I would see the command I had typed into the Windows shell behind the scenes. Very weird! –  Matthew Read Jan 11 '12 at 5:45

Ctrl+\ followed by Enter usually works fine.

This will send a SIGQUIT signal which may not be appropriate for a server (dumps a core file for example) but I don't think it's a problem using this on an Android phone/tablet (which doesn't dump a core file by default). Easy solution that works in most cases.

share|improve this answer

On Windows, you can just enter [Alt]+[3] via the numpad (don't forget to press enter afterwards).
This sends [Ctrl]+[c] to the shell thereby terminating the current command:

D:\Android>adb shell
$ cat
cat
♥
^C

$ exit
exit

D:\Android>

Note that [Alt]+[3] produces the ASCII-Char ♥ in Windows which equals the ETX-Byte.
You can also press [Alt]+[0]-[3] (hold the Alt key down while pressing [0] and [3] on the numpad) if you don't wand windows to display a heart ;)

share|improve this answer

I read a forum post claiming that Ctrl+] worked, but I tried it with no luck. Your mileage may vary. There appears to be no way to have adb pass Ctrl-C on, since it doesn't capture SIGINT. The standard Ctrl-V method doesn't seem to work for Ctrl-C, though it did convert Enter to ^J , unfortunately.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.