• 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: Calling a CLI command withing the app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Calling a CLI command withing the app (From: Jesper Nilsson <email@hidden>)

  • Prev by Date: Re: Coding conventions
  • Next by Date: Context menu for minimised window
  • Previous by thread: Re: Calling a CLI command withing the app
  • Next by thread: Widget Repository?
  • Index(es):
    • Date
    • Thread