Pipe into `adb shell`

前端 未结 3 760
萌比男神i
萌比男神i 2021-02-14 06:29

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

相关标签:
3条回答
  • 2021-02-14 07:07

    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.

    0 讨论(0)
  • 2021-02-14 07:12

    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
    
    0 讨论(0)
  • 2021-02-14 07:32

    Here's my solution. Put the following into the adb_shell.sh file and use it instead of adb shell:

    #!/bin/bash
    
    adb forward tcp:12345 tcp:12345
    adb shell busybox nc -lp 12345 -e "$@" &
    sleep 1s
    exec nc -q 1 localhost 12345
    

    This creates an nc listener which runs the specified command upon the connection, and then connects to it.

    0 讨论(0)
提交回复
热议问题