Hanging NSTask using waitUntilExit
问题 I need to use NSTask synchronously, however I find that occasionally my task hangs under the 'waitUntilExit' command. I wonder if there is a graceful way--an error handling method--to terminated the hanging task so I can re-launch another? 回答1: Note that if the task being run via NSTask fills the output pipe then the process will hang, effectively blocking waitUntilExit from returning. You can prevent this situation by calling [task.standardOutput.fileHandleForReading readDataToEndOfFile];