I am using the following code in my Cocoa project to call a script I made. The script is in the same folder as the project and even shows up under the \"Resources\" folder i
What you will need to do is get the shell binary, and pass your script as an argument. So if the shell script is written targeting bash, get the bash interpreter, and pass it an argument list with one argument: the path to your script.sh.
add this line before [task launch]
:
[task setLaunchPath:@"/bin/sh"];
When I change the name of my script (stored in the App Bundle) from foo.sh
to foo.command
I avoid this error.
let path = Bundle.main.path(forResource: "foo", ofType: "command")
The .command
extension is what is used in the Ray Wenderlich tutorial for NSTask / Process. I can't seem to find this documented anywhere (I also make sure the script is executable via chmod +x foo.sh
).
This error occurs when the script itself is not marked as executable. Open a terminal window and go to where the script is in your project directory, then enter this:
chmod +x script.sh
Clean and build and you can use the script directly - this also means you can pass arguments to it.
because of [task waitUntilExit];