How to embed an executable in my project
Asked Answered
S

1

6

I would like to embed a command-line executable in my Xcode/Cocoa project, to then start it with NSTask. Which path should I use in the setLaunchPath ?

Thanks !

Swamper answered 4/2, 2012 at 22:44 Comment(0)
M
9

you should add it to your resources folder. Then, in runtime, read the app's resource bundle path, and append the name of the executable (including subfolders if you add it to a folder inside the resource bundle)

For instance:

NSString *execPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"binaryname"];

NSTask *task = [[NSTask alloc] init];

[task setLaunchPath: execPath];
Method answered 4/2, 2012 at 23:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.