Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 从Xcode执行shell命令时,如何将参数传递给参数?_Objective C_Xcode_Shell_Command Line Arguments - Fatal编程技术网

Objective c 从Xcode执行shell命令时,如何将参数传递给参数?

Objective c 从Xcode执行shell命令时,如何将参数传递给参数?,objective-c,xcode,shell,command-line-arguments,Objective C,Xcode,Shell,Command Line Arguments,在objective-c中,我可以执行以下操作: NSTask* foo = [NSTask alloc]init]; [foo setLaunchPath:@"/usr/bin/open"]; [foo setArguments:[NSArray arrayWithObjects: @"/foo/foobar.app/foobarbinary, nil]]; /

在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将假定它们是“open”的参数。如果我将其添加到字符串中,就在foobarbinary之后(例如:@“foo/foobar.app/foobarbinary-someargument”),那么“open”假设文件名为“foo/foobar.app/foobarbinary-someargument”

那么我如何将一个论点传递给另一个论点呢


编辑。我尝试在数组中使用--args命令。但是FoobBarbinary似乎没有收到我在--args.后面指定的参数谁有我可以看的例子?

打开命令不允许您这样做。如果您想将参数传递给FoobBarbinary,您必须直接启动它。

它可以工作,谢谢!我没有想到你可以像那样直接调用二进制文件让我们等两分钟再接受答案