Re: Integrating Unix scripting in Cocoa app
Re: Integrating Unix scripting in Cocoa app
- Subject: Re: Integrating Unix scripting in Cocoa app
- From: Alastair Houghton <email@hidden>
- Date: Tue, 7 Aug 2007 15:50:41 +0100
On 7 Aug 2007, at 15:02, Ron Fleckner wrote:
Try it with a script that has arguments on the shebang line, such
as "#!/usr/bin/perl -w -T", or a script that's been written to use
the first available interpreter in your path, like "#!/usr/bin/env
python".
OK, "launch path not accessible" in the run log. I take back
everything I said. Obviously I need to rethink this.
In general, if you're going to do this, you'd have to parse the
command into separate arguments, which is a bit painful as you might
need to handle quoting and the like. Of course, different versions
of Unix do this inconsistently :-)
I would like the user to be able to include a script file without
having to make it executable. Earlier, I had a look to see if
there is a way to determine whether is file is executable, but
didn't find one.
You want to look for the Unix "x" bits. You can read them using
NSFileManager's -fileAttributesAtPath:traverseLink:, then using the -
filePosixPermissions method on the returned dictionary. The downside
is that you then need to use the file's UID and GID, together with
the user's UID and the set of groups to which they belong to
determine whether it's really executable for the current user.
Or you could call access(path, X_OK).
Note, though, that explicitly checking the permissions on files is
generally frowned upon; you can reasonably do it e.g. to display a
dialog to the user saying "That isn't executable", but you can easily
create security problems if you do it without thinking.
**Anyway**, it's probably best to actually try to run the script
directly (i.e. by using its path as the launch path) and then report
an error if you can't, rather than trying to check things up front.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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