0

我有一个应用程序: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

4

1 回答 1

2

要启动可执行程序,无需使用open. 您可以将 NSTask 启动路径设置为您的 texturepacker 二进制文件,然后您可以将 setArguments 设置为包含 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];
于 2012-03-22T15:38:35.857 回答