直接上代码
1 2 3 4 5 6 7 8 9 10 11 12 |
let task = NSTask() task.launchPath = "/bin/echo" task.arguments = ["first-argument", "second-argument"] let pipe = NSPipe() task.standardOutput = pipe task.launch() let data = pipe.fileHandleForReading.readDataToEndOfFile() let output: String = NSString(data: data, encoding: NSUTF8StringEncoding) print(output) |