• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Integrating Unix scripting in Cocoa app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Integrating Unix scripting in Cocoa app


  • Subject: Re: Integrating Unix scripting in Cocoa app
  • From: Marcel Weiher <email@hidden>
  • Date: Wed, 8 Aug 2007 21:29:20 -0700


On Aug 8, 2007, at 5:06 AM, Ron Fleckner wrote:

A generalized approach to running scripts should look like the following:


1. Is it executable? If so, run it directly.

2. Does it have a shebang? If so, either set its executable bit and run it. (You can also try parsing the first line yourself if you don't want to modify permissions, but this is easy to get wrong, particularly when multiple arguments are involved.)

 3. Is the extension known? If so, use an appropriate interpreter.

4. Complain. Any guess you make at this point is likely to be wrong, so it's best to just ask the user to give you a hand.


*: I'm not sure how you'd do this, besides sniffing the extension or using some really nasty heuristics.


As a workable approach, I've settled (I think) on #3 above.

Hmm...I had interpreted that as a series of steps, not as alternatives.

That is, keep a list of allowable extensions and run with the appropriate interpreter.

As others have pointed out, that is OK as a fallback, but probably not generally.


As for the other approaches, they're simply too complex and beyond my current skills to implement effectively.

1. Check wether file is executable:

[[NSFileManager defaultManager] isExecutableFileAtPath:path];

2a. Check wether file starts with shebang

[[NSString stringWithContentsOfFile:path] hasPrefix:@"#!"];

2b. Make file executable

(This actually seems a bit cumbersome with NSFileManager APIs...so switching to libc. Hmm...of course, this now also has code that can be used to check if the file is executable.)

	#include <sys/stat.h>
	#include <sys/types.h>

{
struct stat statbuf;
stat( [path fileSystemRepresentation] , &statbuf );
chmod( [path fileSystenRepresentation] ,statbuf.st_mode | S_IXUSR ); // make executable for owner only
}


Add error checking to taste.	

Marcel

_______________________________________________

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


References: 
 >Re: Integrating Unix scripting in Cocoa app (From: Craig Hunter <email@hidden>)
 >Re: Integrating Unix scripting in Cocoa app (From: Ron Fleckner <email@hidden>)
 >Re: Integrating Unix scripting in Cocoa app (From: Andrew Farmer <email@hidden>)
 >Re: Integrating Unix scripting in Cocoa app (From: Ron Fleckner <email@hidden>)

  • Prev by Date: Re: string encoding in NSMutableData
  • Next by Date: Issues With JAWT_MacOSXDrawingSurfaceInfo
  • Previous by thread: Re: Integrating Unix scripting in Cocoa app
  • Next by thread: Re: Integrating Unix scripting in Cocoa app
  • Index(es):
    • Date
    • Thread