How to get the executable path of a command line tool in Objective-C (Foundation framework)?

I am trying to find a way to determine the executable path of a command line tool in Objective C.

Therefore, if the executable is / Applications / Utils / MyTool, then this method will return / Applications / Utils

I use the Foundation framework.

+3
source share
2 answers

I assume that /Applications/Utils/MyToolyou mean an application named "MyTool" in the "Utils" directory in the "Application" directory (this is actually the way to go /Applications/Utils/MyTools.app). In this case, you can get the directory where the application ( /Applications/Utils) is located , with the following bit of code:

NSString *appParentDirectory = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
+6
source

- ... ""

NSString *myLittleCLIToolPath = NSProcessInfo.processInfo.arguments[0];

+6

Source: https://habr.com/ru/post/1733914/


All Articles