Jump to content
5 posts in this topic

Recommended Posts

Hello:

 

I have been playing around with xcode a little bit recently, and have not been able to figure out how to run a bash shell script right from an implementation file. I looked into NSTask, but couldn't understand how to use it.

 

Is there a simple code block with a place to insert a shell script into it? If I could have some assistance with this it would be greatly appreciated. Thanks!

Here's an example of running a shell script. The actual program being called, sh, is the program that runs the script. Assume the script was called sscript.sh and was in your resources project folder…

NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/bin/sh"];
[task setArguments:[NSArray arrayWithObjects:[[NSBundle mainBundle] pathForResource:@"sscript" ofType:@"sh"], nil]];
[task launch];

 

setArguments: uses an NSArray to supply arguments to the task — in this case, the location of your script.

  • 2 weeks later...

Thanks for the replies; is there any way to insert a direct shell script into the code?

 

Let's say:

touch /Users/myusername/hello.text hellowhatever

etc.....

×
×
  • Create New...