Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在adb外壳命令行中将1个命令的输出管道化到其他命令_Android_Shell_Pipe_Adb - Fatal编程技术网

Android 在adb外壳命令行中将1个命令的输出管道化到其他命令

Android 在adb外壳命令行中将1个命令的输出管道化到其他命令,android,shell,pipe,adb,Android,Shell,Pipe,Adb,我希望向Android设备发送一个adb shell命令,将1个命令的输出传输到另一个命令,但当我尝试这样做时,只有第一个命令在设备上执行,第二个命令在主机上执行。以下是我尝试过的: adb shell command1 | command2 adb shell "command1 | command2" command1在设备上执行,command2在主机上执行 我怎样才能让它正常工作 谢谢 一种方法是创建包含所需命令的shell脚本,然后运行shell脚本 由于Android根文件系统在

我希望向Android设备发送一个adb shell命令,将1个命令的输出传输到另一个命令,但当我尝试这样做时,只有第一个命令在设备上执行,第二个命令在主机上执行。以下是我尝试过的:

adb shell command1 | command2
adb shell "command1 | command2"
command1在设备上执行,command2在主机上执行

我怎样才能让它正常工作


谢谢

一种方法是创建包含所需命令的shell脚本,然后运行shell脚本

由于Android根文件系统在运行时是不可写的(通常,除非您已将设备根化并重新安装),因此您可以将文件复制到可移动(或模拟)存储,例如
/sdcard


然后使用命令
adb shell sh/sdcard/your script name
运行脚本。由于每个脚本都在其自己的子shell中运行,因此您的两个命令都将在设备上的同一shell中执行(您可以使用
ps
进行确认)。

您可以使用以下方法:

例如:

/system/lib下包含“foo”的所有文件的递归列表:

adb shell "cd /system/lib&&ls -lR .|grep -i foo"
重要的是双引号和双符号


唯一的问题是,您不能将其用于输入,这意味着运行一个需要stdin的可执行文件(使用一个线性程序)将无法工作,因为它需要用户干预。

我将尝试这样做。如果command1包含它自己的引号呢?例如,echo“123”?你需要避开这些,或者使用单引号和双引号的组合。这是我最初的想法,但我认为可能有办法绕过它。
adb shell "cd /system/lib&&ls -lR .|grep -i foo"