Re: Calling a script with Xcode 4
Re: Calling a script with Xcode 4
- Subject: Re: Calling a script with Xcode 4
- From: Jens Alfke <email@hidden>
- Date: Wed, 05 Oct 2011 21:20:32 -0700
On Oct 5, 2011, at 6:18 PM, cptkrf wrote:
> In Xcode 3, I would put the scripts and data in (jobfolder)/build/debug and call it, as with --- int result = system("./perlscript.pl"); Worked fine.
That may have worked, but it’s kind of bass-ackwards, if you’ll excuse my French. The build/ folder is for the output of building; you shouldn’t put any source files in there yourself.
If you want a file to become part of the app, add it as a resource to the target and it will be copied in. I’m not sure exactly where it goes if you build a plain command-line target, but if you build some flavor of application it will go into the Contents/Resources subdirectory. The way to find such a file is something like
NSString* path = [[NSBundle mainBundle] pathToResource: @“perlscript” ofType: @“pl”];
It would be better to use NSTask to run the script instead of calling system(). For one thing, it plays better with NSString, and more importantly, it doesn’t parse its input as a command line so it won’t fail if the app is run from a location whose path contains a space character. (There was, infamously, an early iTunes installer that made a similar mistake and ended up erasing your home directory if the name of your disk had a space in it.)
—Jens_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden