网上查到的在处理中文路径时有问题,最后查到了下面的方式:
+ (NSString *)executeCommand: (NSString *)cmd
{
NSString *output = [NSString string];
//这个对中文有问题
//FILE *pipe = popen([cmd cStringUsingEncoding: NSASCIIStringEncoding], "r+");
FILE *pipe = popen([cmd UTF8String], "r");
if (!pipe)
return @"";
char buf[1024];
while(fgets(buf, 1024, pipe)) {
output = [output stringByAppendingFormat: @"%s", buf];
}
pclose(pipe);
return output;
}