Find out location of an executable file in Cocoa

前端 未结 5 1817
北恋
北恋 2021-01-05 15:55

The simple question is: how to find out the location of an executable file in a Cocoa application.

Remember that, in many Unix-like OS people use PATH environment t

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-05 16:40

    Related to Brian Webster's answer:

    An easier way to get the User's shell is to use the NSProcessInfo class. e.g

    NSDictionary *environmentDict = [[NSProcessInfo processInfo] environment];
    NSString *shellString = [environmentDict objectForKey:@"SHELL"];
    

    Which is easier than using dscl and parsing XML input.

提交回复
热议问题