简体   繁体   English

通过Powershell运行ADB命令

[英]Running ADB commands through powershell

so I'm trying to run some ADB commands through a powershell script. 因此,我试图通过Powershell脚本运行一些ADB命令。

This is a simple example of what I am trying to do: 这是我正在尝试做的一个简单示例:

adb shell "
echo "in adb shell"
su root
echo "you are now root."
ls
cd /data/data
echo "in /data/data"
ls
"

I saw in a previous post to add the "" next to shell and at the bottom but that still didn't work for me. 我在上一篇文章中看到在外壳旁边和底部添加“”,但这对我仍然无效。 I can start the shell and the first ls works. 我可以启动外壳程序,并且第一个ls工作。 but it just prints the rest of the commands out instead of doing them. 但是它只是打印其余命令,而不是执行它们。 The output I am getting looks like: 我得到的输出看起来像:

PS C:\Scripts> & .\test.ps1
: not found/sh:
in adb shell
su root
echo you are now root.
ls
cd /data/data
echo in /data/data
MSM8960_lpm.rc
acct
cache
.
.
.
ueventd.qcom.rc 
ueventd.rc 
vendor PS C:\Scripts>

Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks in advance! 提前致谢!

Note: the path to ADB is within the powershell $env:path so the adb commands are working 注意:ADB的路径在powershell $ env:path中,因此adb命令可以正常工作

I was able to get around this by doing: 我可以通过以下方法解决此问题:

adb shell "su -c '[cmd]; [cmd]' " adb shell“ su -c'[cmd]; [cmd]'”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM