To call a shell script from Swift, you can use the system()
function from the Foundation framework. Here’s an example:
main.swift157 chars8 lines
In this example, you create a new Process
object and set the launchPath
to the path of the bash
interpreter. You also set the arguments
property to an array containing the path to your shell script and any arguments you want to pass to it.
Finally, you call launch()
to start the process and waitUntilExit()
to wait until the process has completed.
Make sure that the shell script has executable permissions. You can change the permissions by running the chmod
command in the terminal:
main.swift24 chars2 lines
gistlibby LogSnag