Re: Integrating Unix scripting in Cocoa app
Re: Integrating Unix scripting in Cocoa app
- Subject: Re: Integrating Unix scripting in Cocoa app
- From: Sherm Pendley <email@hidden>
- Date: Tue, 7 Aug 2007 08:45:58 -0400
On Aug 7, 2007, at 8:25 AM, Ron Fleckner wrote:
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?
In that case, you shouldn't be trying to execute it to begin with.
The #! line exists for the kernel's use, not so that you can attempt
to subvert the file permissions the user has chosen.
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]];
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".
sherm--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.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