Skip to content

Instantly share code, notes, and snippets.

@aalemayhu
Created December 27, 2015 19:07
Show Gist options
  • Save aalemayhu/eba08e4a2f4deb58e38e to your computer and use it in GitHub Desktop.
Save aalemayhu/eba08e4a2f4deb58e38e to your computer and use it in GitHub Desktop.
playing
import Foundation
func cmd(launchPath: String, args: [String]?) -> NSString? {
let task = NSTask()
task.launchPath = launchPath
if let arguments = args {
task.arguments = arguments
}
let pipe = NSPipe()
task.standardOutput = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = NSString(data: data, encoding: NSUTF8StringEncoding)
return output
}
func usage() {
print("swft-builder COMMAND <OPTIONS IF ANY>")
}
let args = Process.arguments
guard args.count > 1 else {
usage()
exit(-1)
}
var options: [String]?
let relativePath = args[1]
print("Application is \(relativePath)")
if args.count > 2 {
options = [String](args[2...args.count-1])
}
if let output = cmd(relativePath, args: options) {
print("output: \(output)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment