• 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: Andrew Farmer <email@hidden>
  • Date: Wed, 8 Aug 2007 04:08:25 -0700

On 08 Aug 07, at 02:58, Ron Fleckner wrote:
On 08/08/2007, at 6:28 AM, Craig Hunter wrote:
Take a look at the shell's "source" command, which will load and execute
commands from a text file with no other requirements:


    source file.txt

This might give you an additional option. Perhaps you can check to see if
the file is executable and/or if it includes the shebang. If not, then
conclude it's merely a text file containing shell commands and pass it along
to "source" to run.


But here's something interesting: according to a simple "hello world" script
I just tested, source will even handle text files that have execute
permission set and contain a shebang (ie, real scripts). If that turns out
to be true in general, then you can let the source command execute anything
designated as a script by the user. I'd recommend testing it out.

Well that sounds pretty interesting. I don't have the energy to investigate it right now (too much to do!), but I certainly will look at "source" as a generic script runner. When you say "shell", which one do you mean?

Don't bother. If you can determine that a file lacking a shebang is indeed a shell script* you can just pass it as an argument to /bin/ bash (or whatever shell you deem appropriate). Methods such as passing the shell a wrapper script which invokes 'source' or sending it a 'source' command through a pipe are unnecessarily circuitous.


And, as I noted in an earlier email, it's entirely useless (and possibly harmful) if you're dealing with anything other than shell scripts.

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.
_______________________________________________


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


  • Follow-Ups:
    • Re: Integrating Unix scripting in Cocoa app
      • From: Ron Fleckner <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>)

  • Prev by Date: Re: NSScroller icon / split view
  • Next by Date: [OT] Re: Cocoa and messages to nil, revisited
  • Previous by thread: Re: Integrating Unix scripting in Cocoa app
  • Next by thread: Re: Integrating Unix scripting in Cocoa app
  • Index(es):
    • Date
    • Thread