是否可以更容易解析的格式获取ioreg的输出? [英] Is it possible to get the output of ioreg in a more easily parse-able format?

查看:136
本文介绍了是否可以更容易解析的格式获取ioreg的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取Mac OS X中ioreg的输出以进行进一步处理,但是它使用的树状结构很难解析吗?有什么方法可以获取XML输出或更容易解析的内容(例如system_profiler)?

I need to get the output of ioreg in Mac OS X for further processing, however the tree like structure it uses is difficult to parse? Is there any way to get the output in XML or something easier to parse (like system_profiler)?

+-o Root  <class IORegistryEntry, retain 12>
  | {
  |   ...
  | }
  | 
  +-o MacBookPro5,1  <class IOPlatformExpertDevice, registered, matched, active, busy 0, retain 25>
    | {
    |   ...
    | }
    | 
    +-o AppleACPIPlatformExpert  <class AppleACPIPlatformExpert, registered, matched, active, busy 0, retain 51>
    | | {
    | |   ...

推荐答案

获取ioreg的源代码并对其进行修改很长的路要走...

A long road can be to grab the source code to ioreg and modify it...

https://opensource.apple.com/source/IOKitTools/IOKitTools-108/ioreg.tproj/

下载:

  • ioreg.c
  • IOKitLibPrivate.h
  • IOKitKeysPrivate.h

#include <IOKit/IOKitLibPrivate.h>#include <IOKit/IOKitKeysPrivate.h >更改为#include "IOKitLibPrivate.h"#include "IOKitKeysPrivate.h",以便当两个文件位于同一目录中时可以进行编译,然后使用

Change the #include <IOKit/IOKitLibPrivate.h> and #include <IOKit/IOKitKeysPrivate.h > to #include "IOKitLibPrivate.h" and #include "IOKitKeysPrivate.h" so you can compile when both files is in same directory, then compile with

cc -o ioreg ioreg.c -framework Foundation -framework IOKit -lcurses

这篇关于是否可以更容易解析的格式获取ioreg的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆