0

我正在尝试通过 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];

如果我做错了什么,谁能建议我?

4

1 回答 1

1

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

尝试:

[theTopsCommand setArguments:[NSArray arrayWithObjects:@"replace", @"__My_CompanyName__", @"with", @"XYZ", self.selectedFilePath, nil]];
于 2012-09-10T07:13:39.727 回答