问题
In Cocoa, I would like to pass a string containing special characters to an NSTask as arguments, however the task does not get the proper string.
NSString *city=@"Zürich"; // This is the string with a special character
[arguments addObject:[NSString stringWithFormat:@"-iptc:city=%@",city]];
NSTask *task=[NSTask new];
[task setLaunchPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"exiftool"]];
[arguments addObjectsFromArray:[NSArray arrayWithObjects:@"-L",@"-overwrite_original_in_place",@"filename", nil]];
[task setArguments:arguments];
[task setStandardOutput:[NSPipe pipe]];
[task launch];
The task does not get Zürich as argument but Zürich. Any idea how to properly pass strings with special characters ? I've tried UTF8String but without success. Thanks.
回答1:
The -L argument in exiftool was forcing Latin characterset. Removing it made it work properly.
来源:https://stackoverflow.com/questions/23816347/cannot-pass-special-characters-to-an-nstask