Re: Integrating Unix scripting in Cocoa app
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