tops命令在通过NSTask执行时给出错误

时间:2012-09-10 07:09:28

标签: cocoa nstask

我正在尝试通过NSTask使用 tops 命令:

tops replace "__My_CompanyName__" with "XYZ" TryItOut.m

但它始终给出以下错误:

File replace "__My_CompanyName__" with "XYZ" does not exist

通过终端执行时,它可以正常工作。

以下是我使用的代码:

NSTask *theTopsCommand = [[NSTask alloc] init];
[theTopsCommand setLaunchPath:@"/usr/bin/tops"];
[theTopsCommand setArguments:[[NSArray alloc] initWithObjects:@"replace \"__My_CompanyName__\" with \"XYZ\"", self.selectedFilePath,nil]];
[theTopsCommand launch];
[theTopsCommand waitUntilExit];

如果我做错了什么,有人可以建议我吗?

1 个答案:

答案 0 :(得分:1)

您需要将tops的参数作为字符串数组提供,但是您提供一个字符串。

尝试:

[theTopsCommand setArguments:[NSArray arrayWithObjects:@"replace", @"__My_CompanyName__", @"with", @"XYZ", self.selectedFilePath, nil]];