0

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?

1 Answer 1

1

try adding this to your cmd command and before the Android so it will look like this :

 String cmd = "cmd /c start  android update project -p d://code//android//projects//Testproject2";
Sign up to request clarification or add additional context in comments.

1 Comment

I'm having the same issue.. but your solution doesn't seems to work for me - I'm using Ubuntu. any ideas? thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.