/ Published in: Other
let commandOutput = executeCommand("/bin/echo", ["Hello, I am here!"])
println("Command output: \(commandOutput)")
println("Command output: \(commandOutput)")
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
func executeCommand(command: String, args: [String]) -> String { let task = NSTask() task.launchPath = command task.arguments = args let pipe = NSPipe() task.standardOutput = pipe task.launch() let data = pipe.fileHandleForReading.readDataToEndOfFile() let output: String = NSString(data: data, encoding: NSUTF8StringEncoding) return output }
URL: http://square-the-circle.com/2014/08/03/executing-a-system-command-from-a-macos-app-swift/