10.7 이후 새 API가 있으므로 NSNotifications를 사용하지 않아도됩니다.
task.standardOutput = [NSPipe pipe];
[[task.standardOutput fileHandleForReading] setReadabilityHandler:^(NSFileHandle *file) {
NSData *data = [file availableData]; // this will read to EOF, so call only once
NSLog(@"Task output! %@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
// if you're collecting the whole output of a task, you may store it on a property
[self.taskOutput appendData:data];
}];
중요 :
귀하의 작업, 당신은 전무에 readabilityHandler 블록을 설정해야 종료
; 그렇지 않으면 읽기가 중단되지 않으므로 높은 CPU 사용량이 발생합니다.
[task setTerminationHandler:^(NSTask *task) {
// do your stuff on completion
[task.standardOutput fileHandleForReading].readabilityHandler = nil;
[task.standardError fileHandleForReading].readabilityHandler = nil;
}];
확실히 맞습니다. (그냥 나 자신을 알아 냈어, 근데, 어쨌든 많이 고마워 !-)) –