private static String getCpu4Windows() {
try {
Process process = Runtime.getRuntime().exec("wmic cpu get name");
process.getOutputStream().close();
Scanner sc = new Scanner(process.getInputStream());
String key = sc.next();
String cpuName = "";
while (sc.hasNext()) {
cpuName += sc.next() + " ";
}
return StringUtil.isEmpty(cpuName) ? null : cpuName.substring(0, cpuName.length() - 1);
} catch (IOException ex) {
ex.printStackTrace();
}
return null;
}
private static String getCpu4Mac() {
try {
Process process = Runtime.getRuntime().exec("sysctl machdep.cpu.brand_string");
process.getOutputStream().close();
Scanner sc = new Scanner(process.getInputStream());
String cpuName = "";
while (sc.hasNext()) {
cpuName += sc.next() + " ";
}
return StringUtil.isEmpty(cpuName) ? null : cpuName.substring(0, cpuName.length() - 1);
} catch (IOException ex) {
ex.printStackTrace();
}
return null;
}
public static String getCpu() {
if (SystemInfo.isWindows()) {
return getCpu4Windows();
} else if (SystemInfo.isMac()) {
return getCpu4Mac();
}
return null;
}
public static void main(String[] args) {
long start = System.currentTimeMillis();
System.out.println(getCpu());
System.out.println("time:" + (System.currentTimeMillis() - start));
}
try {
Process process = Runtime.getRuntime().exec("wmic cpu get name");
process.getOutputStream().close();
Scanner sc = new Scanner(process.getInputStream());
String key = sc.next();
String cpuName = "";
while (sc.hasNext()) {
cpuName += sc.next() + " ";
}
return StringUtil.isEmpty(cpuName) ? null : cpuName.substring(0, cpuName.length() - 1);
} catch (IOException ex) {
ex.printStackTrace();
}
return null;
}
private static String getCpu4Mac() {
try {
Process process = Runtime.getRuntime().exec("sysctl machdep.cpu.brand_string");
process.getOutputStream().close();
Scanner sc = new Scanner(process.getInputStream());
String cpuName = "";
while (sc.hasNext()) {
cpuName += sc.next() + " ";
}
return StringUtil.isEmpty(cpuName) ? null : cpuName.substring(0, cpuName.length() - 1);
} catch (IOException ex) {
ex.printStackTrace();
}
return null;
}
public static String getCpu() {
if (SystemInfo.isWindows()) {
return getCpu4Windows();
} else if (SystemInfo.isMac()) {
return getCpu4Mac();
}
return null;
}
public static void main(String[] args) {
long start = System.currentTimeMillis();
System.out.println(getCpu());
System.out.println("time:" + (System.currentTimeMillis() - start));
}