0
在Objective-C,我可以做到以下几点:如何从Xcode执行shell命令时将参数传递给参数?
NSTask* foo = [NSTask alloc]init];
[foo setLaunchPath:@"/usr/bin/open"];
[foo setArguments:[NSArray arrayWithObjects:
@"/foo/foobar.app/foobarbinary,
nil]];
// Arguments to the command: the name of the
// Applications directory
[foo launch];
// Run the command
[foo release];
问题是,如果foobarbinary接受命令行参数,我该如何通过他们的? :) 如果我将它们添加到NSArray中,那么shell会认为它们是“open”的参数。如果我将它添加到字符串中,紧跟在foobarbinary之后(例如:@“foo/foobar.app/foobarbinary -someargument”),那么“open”假定文件的名称是“foo/foobar.app/foobarbinary - someargument”。
那么如何将参数传递给参数? :S
编辑。我试着在数组中使用--args命令。但似乎foobarbinary没有收到我在--args旁边指定的参数。 :S任何人都有我可以看的例子吗?
它的作品谢谢!我没有想到你可以直接调用这个二进制文件。 :S必须等待两分钟才能接受答案。 :) – 2012-03-22 14:12:42