I want to execute “adb” command using Java.
I tried out as follow:
Process p = Runtime.getRuntime().exec(new String[]{"cmd","/c","adb devices"});
But, I get following error p.getErrorStream():
'adb' is not recognized as an internal or external command,operable program or batch file.
Is there any problem of space between “adb devices”?
How to add space in command?
The problem is not the space, but the fact that
adbis not found (because it’s not on the path).Do one of those two things:
adb.exeresides orPATH(for that command) in a way thatadb.exeis in a directory mentioned inPATH.While both of those are possible with
Runtime.exec(), I’d suggest usingProcessBuilder, because it has a much nicer/easier API.For example to modify the path where the command is executed do this: