NSTask setLaunchPath Objective-C Cocca
这是一个非常简单的问题。我在与 Cocoa 应用程序相同的文件夹中有一个脚本。我似乎无法为 NSTask
的 setLaunchPath
正确设置其路径。请帮忙。
我有一个名为 Project 的文件夹。在它的内部,存在多个文件夹,但我们只关心两个:Classes
(Cocoa 应用程序的源文件位于此处)和 Ruby(这是一个 ruby 服务器文件夹)。我正在尝试调用 Ruby/script/server。我认为它会类似于 ./Ruby/script/server
或 Ruby/script/server
但两者都是错误的。
谢谢。
编辑:我想我实际上要问的是是否有一种方法可以使用特殊字符或快捷方式访问源文件或项目所在的文件夹,因为默认情况下它会转到 /tmp
文件夹。
This is a very simple question. I have a script in the same folder as the Cocoa app. I can't seem to set the path to it properly for setLaunchPath
for NSTask
. Help please.
I have a folder called 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). I am trying to call Ruby/script/server
. I assumed it would be something like ./Ruby/script/server
or Ruby/script/server
but both are wrong.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应用程序中的当前目录(在 Unix 意义上)不保证是任何内容。可以通过获取主应用程序包然后获取
其路径来获取应用程序本身的路径
但是请不要这样做;如果没有额外的说明将文件放在各处,您将无法分发您的应用程序。
相反,请将 Ruby 代码放入
yourApp.app/Contents/Resources/
中。这可以通过将 Ruby 代码包含在 XCode 中并确保将其设置为复制到应用程序中来完成。可以通过以下方式获取此Resources
目录中的文件:要了解有关捆绑包结构的更多信息,请阅读 捆绑包编程指南。
The current directory (in the unix sense) in an app is not guaranteed to be anything. The path to the app itself can be obtained by getting the main app bundle by
and then getting its path
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/
. This can be done by including the Ruby code in the XCode, and making sure it's set to be copied into the app. The files inside thisResources
directory can be obtained as follows:To learn more about the bundle structure, read Bundle Programming Guide.