In my cocoa app I have to call system() function to launch an external app. The command I use is:
system("./main &");
If I run the app from Xcode, it works fine, because I know the folder where to put main.
If I create an archive, and distribute my .app application, system() can’t find “main”. Where I have to put it?? Or otherwise, how can I run an app using “./” when I’m not in the folder the application is?
EDIT: Maybe I solved using NSTask, but how can I run “main” in background? Now it opens in a new terminal window.
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/Applications/Multibo/main"];
[task setArguments:[NSArray arrayWithObjects:[NSString stringWithFormat:@"./main &"], nil]];
[task launch];
Thanks
Try appending the full path before the executable’s name and use it as an argument to
system. Note thatsystemis implementation defined — its behavior is not guranteed to be the same across systems and its usage is thus not recommended. You should probably look for a suitable alternative such asNSWorkspace.