Posts

Showing posts with the label process

Xcode/Swift: How to add extra argument to a bash execution

Xcode/Swift: How to add extra argument to a bash execution I have this Code: func syncShellExec(path: String?) { let script = [path!] let process = Process() let outputPipe = Pipe() let filelHandler = outputPipe.fileHandleForReading process.launchPath = "/bin/bash" process.arguments = script process.standardOutput = outputPipe . . . In Swift I call it this way: self.syncShellExec(path: Bundle.main.path(forResource: "initial", ofType: "command")) Now I want to add an Extra argument for the script itself (using Functions within the Bashscript). In Terminal it would be like this: /usr/bin/bash initial.command Do_My_Function How to add this to the process? 1 Answer 1 You can add a “variadic parameter” to your Swift function, and append the arguments to process.arguments : process.arguments...