Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Launching Application with arguments



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>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.