【发布时间】:2013-03-19 14:29:11
【问题描述】:
我已经阅读了使用 NSTask 执行此操作的解决方案:它们看起来都非常长...所以我设法使用此代码执行完全相同的操作(同时获得标准输出和标准错误):
NSTask *task = [NSTask new];
[task setLaunchPath:@"/bin/sh"];
[task setArguments:@[ @"-c", @"aCommand"]];
NSString *stringToRemove = [task description];
[task launch];
NSString *output = [[task description] stringByReplacingOccurrencesOfString:stringToRemove withString:@""];
使用此解决方案有什么缺点吗?有没有更短的方法来过滤输出?
【问题讨论】:
标签: objective-c shell command nstask