I am trying to execute the following command in java.
android update project -p d:\code\android\projects\Testproject2
It executes fine in command-line and does exactly what is expected.
But, when I want to execute this command from java program. It gives error.
My java program code.
String cmd = "android update project -p d://code//android//projects//Testproject2";
try {
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
while(true){
String line = b.readLine();
if(line == null)break;
System.out.println(line);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("command execution failed");
}
and the error I see in the console :
java.io.IOException: Cannot run program "android": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at com.test.commandline.Main.main(Main.java:24)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessImpl.create(Native Method) at java.lang.ProcessImpl.(Unknown Source) at java.lang.ProcessImpl.start(Unknown Source) ... 5 more command execution failed
It seems it can't find 'android' as a command while executing from java. How to fix this problem?