String machineId = null;
final Runtime systemShell = Runtime.getRuntime();
final String cmd = "system_profiler SPHardwareDataType";
System.out.println("cmd=" + cmd + "\n");
final Process output = systemShell.exec(cmd);
final BufferedReader br = new BufferedReader(new InputStreamReader(output.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
try {
System.out.println("C: reading line ...");
Thread.sleep(100);
} catch (final InterruptedException ex) {
}
System.out.println("line=" + line + "\n");
if (line.contains("Serial")) {
machineId = line.trim();
break;
}
}
br.close();
output.destroy();
if (output.exitValue() != 0) {
System.out.println("could not run for macos machine id. exit value={}" + output.exitValue());
throw new RuntimeException("could not get machine id");
}
if (machineId == null) {
System.out.println("Could not get machine id");
}
machineId = StringReplace.replace(machineId, "Serial Number (system):", "");
machineId = StringReplace.replace(machineId, " ", "");
System.out.println("machineId(raw)=" + machineId + "\n");
return new String[] { machineId, machineId, machineId, machineId };