Created
December 31, 2014 08:34
-
-
Save chsh/05d7549a81e331cd90d2 to your computer and use it in GitHub Desktop.
Run NSTask in background for Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var taskQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0) | |
dispatch_async(taskQueue, { () -> Void in | |
let task = NSTask() | |
task.launchPath = "/bin/ls" | |
task.arguments = [] | |
let pipe = NSPipe() | |
task.standardOutput = pipe | |
task.launch() | |
let data = pipe.fileHandleForReading.readDataToEndOfFile() | |
var dataString = NSString(data: data, encoding: NSUTF8StringEncoding) | |
NSLog(dataString) // TODO: write your own code | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment