Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
Ok, I have this code for this program that creates symbolic links. When the create symbolic link button is pressed this code is executed:

Code:
   [symLinkTask setArguments:[NSArray arrayWithObjects:@"-s", sourcePath, targetPath, nil]];
        
        [symLinkTask launch];
        [symLinkTask waitUntilExit];

Then an alert pops up and when the OK button is return and I terminate the NSTask.

Using this:

Code:
        [symLinkTask terminate];

But when I press the button a second time I get this error:
Code:
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'task already launched'

Which is weird because the NSTask should not be running.
 

Thanks chown33 I will use this. It's worth noting that I am using a NSURL to get the path of the original file so I will have to convert the NSURL to a const char?
Or convert the NSURL to a NSString using:
Code:
NSString *myNewString = [path1 absoluteString];
? and then to. Const char?

----------

https://developer.apple.com/library...Classes/NSTask_Class/Reference/Reference.html



The error isn't that the task is still running. It's that the task has already run and completed, and can't be started again. You'll need to create a new NSTask object to run the task again. But chown's suggestion of using the C function is a better solution.

Thanks for your help :)
 
Last edited:
Thanks for your help chown33 but I think I will create my symlink with the NSFileManager instead. :)

That also works.

By prompting you to look for a simpler solution (a C function), you found a different and also simpler solution. A lot of programming is about finding a simpler solution, rather than trying to make a complex one work.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.