Re: Getting processor description from sysctl
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com On 08-05-14, at 21:41, Mike wrote: Maybe: system_profiler -xml SPHardwareDataType Or if you want to avoid Objective C, parsing XML, or using TCL: #define CMD "/usr/sbin/system_profiler SPHardwareDataType" #define TAG "Processor Name: " #define UNK "UNKNOWN" char * get_cpu_name(void) { static char cpu_name[128] = UNK; char buf[sizeof(cpu_name)]; char *p; char *q; FILE *fp; -- Terry _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... On May 14, 2008, at 11:26 PM, Philip Aker wrote: System Profiler provides the processor name, so there must be a way to get it. For example on the MacBook it reports: Processor Name: Intel Core 2 Duo In C, not from a shell script. [ ... cute TCL thing elided ... ] /* Cache results for subsequent calls */ if (!strcmp(UNK, cpu_name)) { if ((fp = popen(CMD, "r")) != NULL) { while (fgets(buf, sizeof(buf), fp) != NULL) { if ((p = strstr(buf, TAG)) != NULL) { p += strlen(TAG); if ((q = strchr(p, '\n')) != NULL) *q = 0; strcpy(cpu_name, p); break; } } fclose(fp); } } return(cpu_name); } ...obviously, this could also be done associatively, with or without the TCL, to capture all the information in a single run of system_profiler so that it could be used as separate name/value pairs, and you could look up the value for any name. It's just not that hard to do this sort of thing without resorting to interfaces that might break each time there's a software update. Now the original poster has two examples. This email sent to site_archiver@lists.apple.com
participants (1)
-
Terry Lambert