简体   繁体   English

NSTask setLaunchPath Objective-C科卡

[英]NSTask setLaunchPath Objective-C Cocca

This is a very simple question. 这是一个非常简单的问题。 I have a script in the same folder as the Cocoa app. 我在与Cocoa应用程序相同的文件夹中有一个脚本。 I can't seem to set the path to it properly for setLaunchPath for NSTask . 我似乎无法为setLaunchPathNSTask正确设置路径。 Help please. 请帮助。

I have a folder called Project. 我有一个名为Project的文件夹。 Inside of it, exist multiple folders but only two we care about: Classes (the source files for the Cocoa app are here) and Ruby (which is a ruby server folder). 在其中,存在多个文件夹,但我们只关心两个文件夹: Classes (可可应用的源文件在这里)和Ruby(这是ruby服务器文件夹)。 I am trying to call Ruby/script/server . 我正在尝试调用Ruby/script/server I assumed it would be something like ./Ruby/script/server or Ruby/script/server but both are wrong. 我以为它会是./Ruby/script/serverRuby/script/server但是两者都是错误的。

Thanks. 谢谢。

EDIT: I guess what I'm actually asking is if there is a way to access the folder where the source files or the project is by using a special character or shortcut because by default it goes to the /tmp folder. 编辑:我想我实际上要问的是是否有一种方法可以通过使用特殊字符或快捷方式来访问源文件或项目所在的文件夹,因为默认情况下它将进入/tmp文件夹。

The current directory (in the unix sense) in an app is not guaranteed to be anything. 应用程序中的当前目录(就Unix而言)不能保证为任何目录。 The path to the app itself can be obtained by getting the main app bundle by 可以通过以下方式获取主应用程序捆绑包,以获取应用程序本身的路径:

NSBundle*mainBundle=[NSBundle mainBundle];

and then getting its path 然后得到它的路

NSString*path=[mainBundle bundlePath];

However please don't do that; 但是请不要那样做。 you won't be able to distribute your app without extra instructions of putting files here and there. 如果没有额外的文件放置说明,您将无法分发您的应用程序。 Instead, put your Ruby code inside yourApp.app/Contents/Resources/ . 而是将您的Ruby代码放入yourApp.app/Contents/Resources/ This can be done by including the Ruby code in the XCode, and making sure it's set to be copied into the app. 这可以通过在XCode中包含Ruby代码并确保将其设置为复制到应用程序中来完成。 The files inside this Resources directory can be obtained as follows: 可以按以下方式获取此Resources目录中的文件:

NSString*path=[mainBundle pathForResource:@"rubyServer" ofType:@"rb"];

To learn more about the bundle structure, read Bundle Programming Guide . 要了解有关包结构的更多信息,请阅读《 包编程指南》

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM