Runtime.getRuntime().exec(cmd)执行adb shell脚本可能出现的问题

Posted mickyliu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Runtime.getRuntime().exec(cmd)执行adb shell脚本可能出现的问题相关的知识,希望对你有一定的参考价值。

例如:adb shell sendevent /dev/input/event3 1 $((0xca)) 1
上面语句中含有$((0xca)) ,执行Runtime.getRuntime().exec("sendevent /dev/input/event3 1 $((0xca)) 1"),不会报错,但也不会生效,解决办法为:

(1)先将$((0xca))中的0xca的十六进制转换为十进制202,$((202)),再执行Runtime.getRuntime().exec("sendevent /dev/input/event3 1 $((202)) 1"),但还是不会报错,但不能生效。

(2)最后将$((202))的$(())去掉,就剩下202,执行Runtime.getRuntime().exec("sendevent /dev/input/event3 1 202 1"),执行后生效,问题解决。


以上是关于Runtime.getRuntime().exec(cmd)执行adb shell脚本可能出现的问题的主要内容,如果未能解决你的问题,请参考以下文章

Android Runtime.getRuntime().exec

如何与 Runtime.getRuntime().exec(command) 程序进行交互?

在循环中运行“Runtime.getRuntime()。exec()”

Runtime.getRuntime.exec()执行java进程失败

无法从 Java 进程(Runtime.getRuntime().exec() 或 ProcessBuilder)读取 InputStream

Runtime.getRuntime.exec()执行linux脚本导致程序卡死有关问题