如何在目标c中使用变量E.G运行shell命令 system(“thisCMD thisParam%@”,username);
答案 0 :(得分:1)
[NSTask launchedTaskWithLaunchPath:@"thisCMD" arguments:[NSArray arrayWithObject:username]];
或者如果username
不是字符串:
[NSTask launchedTaskWithLaunchPath:@"thisCMD" arguments:[NSArray arrayWithObject:[username description]]];
或者,如果您希望能够将每个参数的格式说明符更改为稍后更复杂的内容:
[NSTask launchedTaskWithLaunchPath:@"thisCMD" arguments:[NSArray arrayWithObject:[NSString stringWithFormat:@"%@", username]]];