I'm attempting to use Adobe AIR NativeProcess in a Flex application to generate an XML file that I can parse to get various system information on a Mac (I have the equivalent working on Windows and I'm not very familiar with the Mac). I need information mostly about the CPU.
I'm unable to call the system profiler and pass the proper parameters (or any parameters) to get the NativeProcess to execute properly.
If I set the NativeProcess executable to:
/Applications/Utilities/System Profiler.app/Contents/MacOS/System Profiler
it executes, but I see the results popup on screen (it ignores my arguments to save it to a file which I believe makes sense since it is the GUI version).
If I set the NativeProcess executable to:
user/sbin/system_profiler or just system_profiler
nothing executes and I receive an ArgumentError #2004 on the line where I assign the executable.
The parameters are something like this:
systemDataMac.npArgList = ["-xml",">", systemDataFileName,"-detailLevel","basic"];
How can I get this file generated properly (or is there any other way to get the CPU information directly into my Flex/AIR app?
Thank you!
Sample Code:
var nativeProcess:NativeProcess=new NativeProcess();
var startupInfo:NativeProcessStartupInfo=new NativeProcessStartupInfo();
var npArgs:Array = [];
var appDataDir:File = File.applicationStorageDirectory;
var nativeFilePath:String = appDataDir.nativePath.toString();
nativeFilePath+= File.separator + "systemInfoFile.xml";
nativeProcess.addEventListener(NativeProcessExitEvent.EXIT, onExit);
nativeProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
nativeProcess.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
nativeProcess.addEventList开发者_如何学运维ener(IOErrorEvent.STANDARD_INPUT_IO_ERROR, onInputIOError);
nativeProcess.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onOutputIOError);
try
{
// tried each of these three
startupInfo.executable=new File("system_profiler"); // throws error
startupInfo.executable=new File("/user/sbin/system_profiler"); // throws error
startupInfo.executable=new File("/Applications/Utilities/System Profiler.app/Contents/MacOS/System Profiler"); // works but doesn't handle args because it is the GUI version I believe
npArgs = ["-xml",">", nativeFilePath,"-detailLevel","basic"];
var args:Vector.<String>=new Vector.<String>();
for each(var item:String in npArgs)
{
args.push(item);
}
startupInfo.arguments=args;
nativeProcess.start(startupInfo);
}
catch (error:IllegalOperationError)
{
trace("Illegal Operator Error - " + error.toString());
}
catch (error:ArgumentError)
{
trace("Arg Error - " + error.toString());
}
catch (error:Error)
{
trace("Error - " + error.toString());
}
What kind of information do you need? Have you had a look at the Capabilities class?
精彩评论