문제

I have an application : TexturePacker. If I click on the application icon in the application folder it launches the gui. If I type "texturepacker" in terminal, it runs the command line version.

I want to launch the command line version programmatically! When I use the code below, it launches the GUI. What shell command should I use so that the application (command line version) launches as if I typed in "texture packer" in terminal.

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];

If this is a noob question. I apologize. I am noobtastic. :S

EDIT: Figured out part of it. I needed to specify the path to the binary inside the app to launch it. But How do I pass arguments to that? If I add any more arguments to the array, the shell assumes that it is an argument to the "open" command. If I add it to the string with the path to texture packer, the shell says the application is not found. :S

도움이 되었습니까?

해결책

For launching an executable program, there is no need to use open. You can set the NSTask launch path to your texturepacker binary, and then you can setArguments to an array containing the arguments for 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];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top