NSTask setLaunchPath Objective-C Cocca

发布于 2024-09-08 21:52:43 字数 449 浏览 2 评论 0原文

这是一个非常简单的问题。我在与 Cocoa 应用程序相同的文件夹中有一个脚本。我似乎无法为 NSTasksetLaunchPath 正确设置其路径。请帮忙。

我有一个名为 Project 的文件夹。在它的内部,存在多个文件夹,但我们只关心两个:Classes(Cocoa 应用程序的源文件位于此处)和 Ruby(这是一个 ruby​​ 服务器文件夹)。我正在尝试调用 Ruby/script/server。我认为它会类似于 ./Ruby/script/serverRuby/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千年*琉璃梦 2024-09-15 21:52:43

应用程序中的当前目录(在 Unix 意义上)不保证是任何内容。可以通过获取主应用程序包然后获取

NSBundle*mainBundle=[NSBundle mainBundle];

其路径来获取应用程序本身的路径

NSString*path=[mainBundle bundlePath];

但是请不要这样做;如果没有额外的说明将文件放在各处,您将无法分发您的应用程序。
相反,请将 Ruby 代码放入 yourApp.app/Contents/Resources/ 中。这可以通过将 Ruby 代码包含在 XCode 中并确保将其设置为复制到应用程序中来完成。可以通过以下方式获取此 Resources 目录中的文件:

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

要了解有关捆绑包结构的更多信息,请阅读 捆绑包编程指南

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

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/. 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 this Resources directory can be obtained as follows:

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

To learn more about the bundle structure, read Bundle Programming Guide.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文