• 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: Permissions problem after NSTask application launch
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Permissions problem after NSTask application launch


  • Subject: Re: Permissions problem after NSTask application launch
  • From: Sherm Pendley <email@hidden>
  • Date: Mon, 18 Apr 2005 00:43:17 -0400

On Apr 18, 2005, at 12:15 AM, David Darby wrote:

- (void)launchStudentVersion
{
    NSTask* task = [[NSTask alloc] init];
    NSMutableArray* args = [NSMutableArray array];
    NSBundle* appBundle = [NSBundle mainBundle];

    

    // set arguments
    NSString* firstCmd;
    NSString* cmd1 = @"/MyApp.app/Contents/MacOS/MyApp";
    NSString* cmd2 = @"-student";
    NSString* path = [[appBundle bundlePath] stringByDeletingLastPathComponent];

    

    firstCmd = [path stringByAppendingString:cmd1];
    [task setLaunchPath:firstCmd];

    

    NSLog(firstCmd);
    [args addObject:firstCmd];
    [args addObject:cmd2];

    

    [task setArguments:args];
    [task launch];

    

    [NSApp terminate:self];    
}

This works as it should, ie when the application is opened from the Finder, it launches the application called "MyApp" which resides in the same directory using the command line option of -student which causes the application to run in "student" mode (with some options disabled). After launching MyApp, this small application politely quits.

However, when the launched application runs in Student mode, it strangely cannot access (due to insufficient privileges) any directory in the same folder.

Have you verified that the errors are definitely due to permissions, rather than "file not found"?

I ask because child processes inherit the working directory of the parent, which is *not* the same directory that the executable is found in. Nor is it always the same - when launched from Finder, it's "/", but when launched from Xcode it's the build directory.

There are two potential solutions to that: First, you could use full paths in your child process. That is, "/full/path/to/file.txt" instead of just "file.txt". Or, you could specify the working directory for the child process to use by calling NSTask's -setCurrentDirectoryPath: method before launching the child.

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net

Hire me! My resume: http://www.dot-app.org


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Permissions problem after NSTask application launch
      • From: David Darby <email@hidden>
References: 
 >Permissions problem after NSTask application launch (From: David Darby <email@hidden>)

  • Prev by Date: Permissions problem after NSTask application launch
  • Next by Date: ColorCell, NSActionCell subclass
  • Previous by thread: Permissions problem after NSTask application launch
  • Next by thread: Re: Permissions problem after NSTask application launch
  • Index(es):
    • Date
    • Thread