Try to read some information from system profiler. For this purpose i m running some terminal line commands with NSTask. If i run some command which output not too big there is no problem.(For example : SPInstallHistoryDataType) But if i run "SPApplicationsDataType" command to collect installed application list, NSTask waits too much without any result and any error.
So i started to thing there should be a buffer size or something like that and i could not find anything about that. I don't know maybe i m on wrong way.
func readData (dataType: String) -> NSArray? {
let out = NSPipe()
let task = NSTask()
task.launchPath = "/usr/sbin/system_profiler"
task.arguments = ["-xml",dataType]
task.standardOutput = out
task.launch()
task.waitUntilExit()
if task.terminationStatus != 0 {
NSLog("system_profiler returned error status")
return nil
}
let data = out.fileHandleForReading.readDataToEndOfFile()
let plist : AnyObject?
do {
plist = try NSPropertyListSerialization.propertyListWithData(data,
options: [.Immutable],
format: nil)
} catch let error as NSError {
NSLog("%@", "Failed to parse system_profiler results. \(error.localizedDescription)")
return nil
}
return plist as? NSArray
}
let r = readData("SPInstallHistoryDataType")// There is no problem
let r2 = readData("SPApplicationsDataType") // Crash
Note : Yes i could write this data to file and read from that file. But i try to understand what is the problem.
It's definitely a buffer issue. When you read a chunk at a time, it works.