我有一个小脚本,可以在安卓手机的 adb shell(/system/etc 目录)中运行,通过发送/接收单个 AT 命令来与调制解调器通信。
如果在 adb shell 中运行该脚本,它可以正常工作。以下是脚本示例:
cat /dev/pts/7 &
echo -e $1\\r > /dev/pts/7
以下是在 adb shell 中的输出:
# ./sendATCommand "at+cops?"
./sendATCommand "at+cops?"
#
+COPS: 0,0,"AT&T",6
OK
/dev/pts/7: invalid length
(need to press ENTER to return control to adb shell)
#
现在我想从我的个人电脑上运行的PowerShell脚本中调用此脚本,从而最终通过AT命令控制调制解调器,但是没有任何反应。 例如,以下PowerShell脚本将发送命令at+cops?以检查手机所注册的运营商:
$adb = [IO.Path]::Combine([IO.Path]::Combine($Env:ANDROID, "platform-tools"), "adb.exe")
& $adb remount
$atCommand = "at+cops?"
& $adb shell /system/etc/sendATCommand $atCommand
输出有时可能看起来像+ATCMD(启动后设备缓冲区中任何剩余的[专有] AT 命令),或at+cops?(echo),或根本没有,但从不是我期望的+COPS: 0,0,“AT&T”,6。你能帮我弄清楚发生了什么,如何可能修复它吗?理想情况下,我希望能够执行 at 命令,将控制返回到 powershell,并且可以对输出进行进一步处理。我也愿意接受实现相同功能的其他解决方案。非常感谢您的帮助。谢谢!
& $adb shell /system/etc/sendATCommand """$atCommand"""
。 - Andy Arismendi