• 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: Launching Application with arguments
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Launching Application with arguments


  • Subject: Re: Launching Application with arguments
  • From: Vince DeMarco <email@hidden>
  • Date: Mon, 19 Nov 2001 21:02:04 -0800

On Monday, November 19, 2001, at 06:27 am, Yves Peneveyre wrote:

Hello the list,

I read the following thread and I extracted some interesting things :

---------
On Thursday, November 15, 2001, at 12:25 PM, Fei Li wrote:

Hello all,
I tried to launch a application named "abc.app" use NSTask, I write code
as follows:
NSArray * args = [[NSArray alloc] initWithObjects:@"2", nil];
[NSTask launchedTaskWithLaunchPath:@"/Users/feil/Desktop/abc.app"
arguments:args];
I always get error message:Task create for path abc.app failed.

You need to run the actual executable file, inside of the app wrapper.
Change the path to "/Users/feil/Desktop/abc.app/Contents/MacOS/abc".
----------

Now, I'd like to retrieve the arguments in the launched application.
Ok, I can modifiy the "main(...)" function to get the arguments,
but I'd like to know if there is an other way to do this......

Any idea ?

If you're command line arguments can look like

-MyCommandLineArg Foo

then you can just use NSUserDefaults

value = [[NSUserDefaults standardUserDefaults] stringForKey:@"MyCommandLineArg"];

if ([value isEqualToString:@"Foo"]){
/* Do stuff cuz MyCommandLineArg is == Foo */
}


This will not work if you have to pass the command line args in a very specific way for other reasons.

else you could do

[[NSProcessInfo processInfo] arguments]

which returns an NSArray of the command line arguments and just parse them your self.

vince


References: 
 >Launching Application with arguments (From: "Yves Peneveyre" <email@hidden>)

  • Prev by Date: Re: Standard OS X Compression format
  • Next by Date: Re: Some questions about cocoa graphics2D
  • Previous by thread: Re: Launching Application with arguments
  • Next by thread: Re: Launching Application with arguments
  • Index(es):
    • Date
    • Thread