objective-c - 如何以编程方式从命令行启动应用程序的命令行版本?

标签 objective-c cocoa texturepacker

我有一个应用程序:TexturePacker。 如果我单击应用程序文件夹中的应用程序图标,它将启动 gui。 如果我在终端中输入“texturepacker”,它将运行命令行版本。

我想以编程方式启动命令行版本!当我使用下面的代码时,它会启动 GUI。我应该使用什么 shell 命令,以便应用程序(命令行版本)启动,就像我在终端中输入“texture packer”一样。

NSTask *theProcess = [[NSTask alloc] init];    
[theProcess setLaunchPath:@"/usr/bin/open"];

[theProcess setArguments:[NSArray arrayWithObjects:
                                @"-a", 
                                @"/Applications/TexturePacker.app",
                                nil]];  
            // Arguments to the command: the name of the
            // Applications directory

            [theProcess launch];
            // Run the command

            [theProcess release];

如果这是一个菜鸟问题。我道歉。我很傻。 :S

编辑:弄清楚其中的一部分。我需要指定应用程序内二进制文件的路径才能启动它。但是我如何传递参数呢?如果我向数组添加更多参数,shell 会假定它是“open”命令的参数。如果我将其添加到带有纹理打包程序路径的字符串中,shell 会说找不到该应用程序。 :S

最佳答案

要启动可执行程序,无需使用 open 。您可以将 NSTask 启动路径设置为您的texturepacker二进制文件,然后您可以将Arguments设置为包含texturepacker参数的数组:

NSTask *theProcess = [[NSTask alloc] init];

[theProcess setLaunchPath:@"/path/to/texturepacker"];

// Set arguments for invoking texturepacker
[theProcess setArguments:[NSArray arrayWithObjects:
                                @"-x", 
                                @"-y",
                                @"-z",
                                nil]];

// Run the task
[theProcess launch];

[theProcess release];

关于objective-c - 如何以编程方式从命令行启动应用程序的命令行版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9823395/

相关文章:

iphone - 编辑开始时更改 UITextField 背景

objective-c - iOS 上的 Cocos2d : 2d billiard zooming

cocoa - NSMetadataQuery 将文档移动到 iCloud 后找不到文档

ios - 在iPhone4上使用OpenGL ES加载大纹理时出现glError 0x0501

java - 多个动画的动画偏移

ios - 当 Cocos2D 2.0 支持 NPOT 纹理时,为什么要使用纹理图集?

iphone - Objective-C 等效于 curl 请求

iphone - 所选单元格的背景图像

cocoa - 如何为具有 "Viewer"角色的应用程序定义可写类型?

cocoa - 为 NSToolbar 制作 NSToolbar 图标