1

I tried below code to get the output of the ran command. But it printing empty.

String cmd = "/bin/bash device_id -l";
Process process = Runtime.getRuntime.exec(cmd);
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
    System.out.println(line);
}
reader.close();

Could anyone please help me. I have to get the connected iDevice UDID.

3
  • Try String cmd = "device_id -l"; Commented Nov 2, 2015 at 12:44
  • That is not working in Mac @jctim Commented Nov 3, 2015 at 7:01
  • I don't know what does your command do, but I tried String cmd = "ps -ef"; and got output in stdout. Maybe your command writes in stderr? Commented Nov 3, 2015 at 12:17

1 Answer 1

1

With the below code I could get the connected device udid.

public String deviceUDID() throws IOException{
        ProcessBuilder builder = new ProcessBuilder("/bin/bash", "-c", "/usr/local/bin/idevice_id -l");
        builder.redirectErrorStream(true);
        Process p = builder.start();
        BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        line = r.readLine();
        System.out.println(line);
        return line;
    }
Sign up to request clarification or add additional context in comments.

Comments

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.