Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipe into `adb shell`

Tags:

android

adb

pipe

Why can I not pipe into adb shell?

[klm@kth ~]$ echo foo | adb shell cat
^C

The above command hangs on my 4.0.1 emulator, and I'm not seeing the expected foo output.

I presume it's because adb shell doesn't pipe its stdin into its child-process' stdout, and cat sits and waits forever. Has this really not been implemented in adb, or am I missing something?

like image 440
kristianlm Avatar asked Mar 07 '13 18:03

kristianlm


People also ask

What is adb shell command?

Android Shell Commands. ADB is Android Debug Bridge which is a command line utility included with Google's Android SDK. It provides a terminal interface to control your Android device connected to a computer using a USB. ADB can be used to run shell commands, transfer files, install/uninstall apps, reboot and more.

How do I run adb shell on Windows?

Open a command window in the folder by holding shift and right-clicking in an empty spot in the folder and selecting "Open command prompt/PowerShell here" in the menu. Then you can start using ADB — connect your phone and try . ADB devices to see if it's working. A list with attached devices should show up.


2 Answers

An alternate option may be to use adb port forwarding and netcat.

Set Android side to recieve:

busybox nc -lp 5555 > piped_file.txt

PC side, set forwarding and send:

adb forward tcp:4444 tcp:5555 # Anything sent to localhost 4444 will be forwarded to Android 5555
cat piped_file.txt | busybox nc localhost 4444 # Pipe through the port to Android

The PC netcat connects to the Android netcat through the forwarded port, and the piped_file.txt is delivered.


Additional Info
Combined with tar, you can copy entire directory structures onto your device.

busybox nc -lp 5555 | tar -x # Android side

adb forward tcp:4444 tcp:5555 # PC side
tar -c directory | busybox nc localhost 4444
like image 149
Rucent88 Avatar answered Nov 01 '22 07:11

Rucent88


This is correct. This functionality has not been implemented.

Update:

A lot of bugs have been fixed and new features implemented in adb since the time the original question had been posted. Including support for proper stdin handling by adb shell. So there is no need for the netcat workarounds anymore.

like image 43
Alex P. Avatar answered Nov 01 '22 07:11

Alex P.