How to run an adb shell command and remain in the

2019-02-17 01:37发布

Does anyone know how to run commands from adb shell and remain in shell session? What I`m trying to achieve is to set aliases in adb shell.

I have tried the following without success

adb shell <<< "ls"

After executing this command indeed remain in shell, but cannot receive output of any further command.

I have also tried the following:

adb shell <<EOF
ls
EOF

with the same result.

3条回答
家丑人穷心不美
2楼-- · 2019-02-17 02:06

expect solution

adb-cmd:

#!/usr/bin/env expect
spawn adb shell
expect "#"
send [ concat [ join $argv " " ] ]
send "\r"
interact

Usage:

adb-cmd 'cd /data/data; ls'

Tested in Ubuntu 16.04 host, Android O guest.

查看更多
We Are One
3楼-- · 2019-02-17 02:21

There was a similar question answered in the comments here.

In short, run the following from your terminal:

stty raw -echo ; ( echo "ls" && cat ) | adb shell ; stty sane

Note: without the stty magic, the command is piped to adb and tab complete etc. is not recognized.

查看更多
Lonely孤独者°
4楼-- · 2019-02-17 02:29

When you run:

adb shell ls

You are running this command currently outside of ADB.

First, you need to enter ADB:

adb shell

Once you enter ADB shell, you can continue to see output and input more commands.

ls
help

To exit ADB, simply type "exit" or hit "Ctrl + C"

查看更多
登录 后发表回答