macprogrammer Posted July 5, 2008 Share Posted July 5, 2008 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! Link to comment Share on other sites More sharing options...
Airr Posted July 5, 2008 Share Posted July 5, 2008 Look into either of the following: Moriarty AMShellWrapper and other stuff They both support redirecting the output to a Cocoa app....might come in handy! AIR. Link to comment Share on other sites More sharing options...
stroke Posted July 8, 2008 Share Posted July 8, 2008 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. Link to comment Share on other sites More sharing options...
macprogrammer Posted July 18, 2008 Author Share Posted July 18, 2008 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..... Link to comment Share on other sites More sharing options...
stroke Posted July 22, 2008 Share Posted July 22, 2008 You could use system() but it's use is proscribed. NSTask would be the proper API supported method of doing it. Link to comment Share on other sites More sharing options...
Recommended Posts