Search code examples
objective-ccocoaspecial-charactersnstasknsstringencoding

Cannot pass special characters to an NSTask


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.


Solution

  • The -L argument in exiftool was forcing Latin characterset. Removing it made it work properly.