If you want to run an terminal command in a swift script? If you don’t use command outputs in Swift code, following would be sufficient:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #!/usr/bin/env swift import Foundation @discardableResult func shell(_ args: String...) -> Int32 { let task = Process() task.launchPath = "/usr/bin/env" task.arguments = args task.launch() task.waitUntilExit() return task.terminationStatus } shell("ls") shell("xcodebuild", "-workspace", "myApp.xcworkspace") |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.