• 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: Ron Fleckner <email@hidden>
  • Date: Tue, 7 Aug 2007 22:25:07 +1000

On 07/08/2007, at 9:52 PM, Sherm Pendley wrote:


On Aug 7, 2007, at 6:38 AM, Ron Fleckner wrote:


My app has a Scripts menu from which the user can run Ruby, Python, Perl and AppleScripts. I want to be able to support shell and other script types and to do so, I need to get the shebang line from the script file and pass that to NSTask.


You don't need to know anything about the shebang line to execute a script with NSTask. Just launch the script directly as an executable, and the kernel will read the shebang line to determine out what interpreter to use.




But if the script is NOT an executable?

If I try this:

	NSTask *task = [[NSTask alloc] init];
	[task setLaunchPath:pathToScript];
	[task launch];
I get:
	launch path not accessible
in Xcode's runlog UNLESS the script is already an executable.

I just want users to be able to add a Unix script of any kind as a plain text file or an exe and run it. For both cases, this works:

NSString *path = [menuItem representedObject];
NSArray *components = [[NSString stringWithContentsOfFile:path] componentsSeparatedByString:@"\n"];
NSString *task = [[components objectAtIndex:0] substringFromIndex:2];
[NSTask launchedTaskWithLaunchPath:task arguments:[NSArray arrayWithObject:path]];




This really has nothing to do with Cocoa, by the way - it's true whether you use NSTask, system(), or any other API to launch the child process.


I think there may be something you're saying which I'm not getting. I'm really not very au faix with anything other than simple C and Cocoa/ObjC. For my purposes, you have answered my question very well. Unless you think the second approach I've written above is not a good idea, I'll go with that.


Thanks for your help,

Ron
_______________________________________________

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: Sherm Pendley <email@hidden>
References: 
 >Integrating Unix scripting in Cocoa app (From: Ron Fleckner <email@hidden>)
 >Re: Integrating Unix scripting in Cocoa app (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Re: Integrating Unix scripting in Cocoa app
  • Next by Date: Re: Integrating Unix scripting in Cocoa app
  • Previous by thread: Re: Integrating Unix scripting in Cocoa app
  • Next by thread: Re: Integrating Unix scripting in Cocoa app
  • Index(es):
    • Date
    • Thread