How to run an adb command through a Java file? -
i have written following code , cannot quite figure out how solve error. not sure if information found useful, using mac , using editor intellij.
public class testcode { public static void main(string[] args) throws exception { runtime runtime = runtime.getruntime(); process process = runtime.exec("adb devices"); } } the result "exception in thread "main" java.io.ioexception: cannot run program "adb": error=2, no such file or directory"
however, when run command "adb devicees" terminal list of devices attached computer.
for interested, following full stack trace.
exception in thread "main" java.io.ioexception: cannot run program "adb": error=2, no such file or directory @ java.lang.processbuilder.processexception(processbuilder.java:478) @ java.lang.processbuilder.start(processbuilder.java:457) @ java.lang.runtime.exec(runtime.java:593) @ java.lang.runtime.exec(runtime.java:431) @ java.lang.runtime.exec(runtime.java:328) @ com.sonos.acr.test.testcode.main(testcode.java:6) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25) @ java.lang.reflect.method.invoke(method.java:597) @ com.intellij.rt.execution.application.appmain.main(appmain.java:120) caused by: java.io.ioexception: error=2, no such file or directory @ java.lang.unixprocess.forkandexec(native method) @ java.lang.unixprocess.<init>(unixprocess.java:53) @ java.lang.processimpl.start(processimpl.java:91) @ java.lang.processbuilder.start(processbuilder.java:452) ... 9 more thank in advance suggestions, advice, and/or help.
you need use exec(string[] cmdarray) function send arguments, single argument version of function splits string on space, , spells trouble if path contains spaces.
you need specify full path (maybe /usr/bin/adb?).
like this:
process process = runtime.exec(new string[] {"/usr/bin/adb", "devices"});
Comments
Post a Comment