How to add a perl/ruby/sh/... script to my application ?
09/07/03 22:51
I need to call an embedded script from my application…
First, you need to decide where you will put the script inside your application bundle: the Resources subfolder is a good candidate.
Then you need to add the script to your project and define a new Copy build phase to move it where you have decide to.
Inside your application code, you will be able to get a path to it by using [[NSBundle mainBundle] pathForResource:@"myscriptname" ofType:@"myscriptextension"]; (pass nil for the extension if there is none).
Calling your script is then a matter of creating a NSTask and attaching pipe(s) to it if you need to get its output back in your code or if you need to feed its stdin from your code.
Note that if your script is not executable at command line (its executable bit is not set) you have to launch it using /bin/sh (or any other valid shell) as the launch path argument and the path to your script as the first argument and then the normal arguments to your script (if any).
Then you need to add the script to your project and define a new Copy build phase to move it where you have decide to.
Inside your application code, you will be able to get a path to it by using [[NSBundle mainBundle] pathForResource:@"myscriptname" ofType:@"myscriptextension"]; (pass nil for the extension if there is none).
Calling your script is then a matter of creating a NSTask and attaching pipe(s) to it if you need to get its output back in your code or if you need to feed its stdin from your code.
Note that if your script is not executable at command line (its executable bit is not set) you have to launch it using /bin/sh (or any other valid shell) as the launch path argument and the path to your script as the first argument and then the normal arguments to your script (if any).