Cannot pass special characters to an NSTask

扶醉桌前 提交于 2019-12-11 23:55:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!