【发布时间】:2012-03-22 22:09:31
【问题描述】:
在objective-c中我可以做到以下几点:
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 假定它们是“打开”的参数。如果我将它添加到字符串中,就在 foobarbinary 之后,(例如:@"foo/foobar.app/foobarbinary -someargument"),那么“open”假定文件的名称是“foo/foobar.app/foobarbinary -一些论点”。
那么如何将参数传递给参数? :S
编辑。我尝试在数组中使用 --args 命令。但似乎 foobarbinary 没有收到我在 --args 中指定的参数。 :S 任何人有一个我可以看看的例子吗?
【问题讨论】:
标签: objective-c xcode shell command-line-arguments