【问题标题】:How to pass an argument to an argument when executing a shell command from Xcode?从 Xcode 执行 shell 命令时如何将参数传递给参数?
【发布时间】: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


    【解决方案1】:

    open 命令不会让你这样做。如果你想将参数传递给 foobarbinary,你必须直接启动它。

    【讨论】:

    • 它有效,谢谢!我没有想到你可以像这样直接调用二进制文件。 :S 必须等待两分钟才能接受答案。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多