Re: Calling a CLI command withing the app
Re: Calling a CLI command withing the app
- Subject: Re: Calling a CLI command withing the app
- From: Douglas Davidson <email@hidden>
- Date: Mon, 29 Oct 2001 09:15:44 -0800
On Saturday, October 27, 2001, at 03:52 AM, Jesper Nilsson wrote:
I have done some CLI apps in C for BSD before. They work great in osX.
But now i want to do a gui wrapper in Cocoa using NSTask. It works if I
use the true path to the CLI app in setLaunchPath. But I want to
include the CLI commands in the app.
How do I call them within the app from objC?
I tried lame things like this:
BitrateCalc = [[NSTask alloc] init];
[avi2mov setLaunchPath:@"myApp.app/resources/BitrateCalculator"];
But it doesn't like the LaunchPath.
You are using a relative path here, which means that you are depending
on the application's current working directory. Do not do that--an
application's current working directory can be anything at all, unless
you have set it yourself. To find resources within your application's
bundle, use NSBundle. In particular, methods like
- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext;
- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext
inDirectory:(NSString *)subpath;
will get the path you want; try something like
[avi2mov setLaunchPath:[[NSBundle mainBundle]
pathForResource:@"BitrateCalculator" ofType:nil]].
By the way, in a standard bundle, Resources is capitalized. Some
filesystems may be case-insensitive, but NSBundle and CFBundle are not.
Douglas Davidson