NSTask with non-ASCII paths
NSTask with non-ASCII paths
- Subject: NSTask with non-ASCII paths
- From: Andrew Zamler-Carhart <email@hidden>
- Date: Fri, 7 Jan 2005 23:45:12 +0000
Greetings,
I have a method that uses NSTask to wrap a command-line tool called
sips (see sips --help for more info). Currently, it works great for
most files. However, files with any non-ASCII characters in their paths
cause this method to fail.
Here is the code that I am using. I need to be able to call
-setCurrentDirectoryPath: and -setArguments: with strings that may
contain foreign-language characters (Russian, Japanese, etc.)
- (int) performSipsTransformation: (NSMutableArray *) arguments {
NSString *parentPath = [absolutePath
stringByDeletingLastPathComponent];
NSString *name = [absolutePath lastPathComponent];
[arguments addObject: name];
NSTask *sipsTask = [[[NSTask alloc] init] autorelease];
[sipsTask setLaunchPath: @"/usr/bin/sips"];
[sipsTask setCurrentDirectoryPath: parentPath];
[sipsTask setArguments: arguments];
[sipsTask launch];
[sipsTask waitUntilExit];
return [sipsTask terminationStatus];
}
When this path, everything works fine:
/Users/kavasoft/Folder/foo.jpg
But these give errors ("Error modifying file"):
/Users/kavasoft/Folder/фу.jpg
/Users/kavasoft/Папка/foo.jpg
/Users/kavasoft/ホールダー/foo.jpg
I have tried experimenting with the NSString method
-fileSystemRepresentation, but it doesn't seem to help matters. I tried
wrapping name and parentPath with this method:
- (NSString *) fileSystemRepresentation: (NSString *) value {
return [NSString stringWithCString: [value
fileSystemRepresentation]];
}
The names get converted into a format like these, with each multi-byte
unichar represented as several characters:
/Users/kavasoft/Folder/—Ñ—É.jpg
/Users/kavasoft/–ü–∞–ø–∫–∞/foo.jpg
/Users/kavasoft/ホールダー/foo.jpg
But those don't work either.
Does anybody have any suggestions for how to convert non-ASCII paths so
that NSTask and sips will communicate properly?
For what it's worth, I tried using NSTask to run ls, and it accepted
the non-ASCII paths just fine. So I'm not sure how ls and sips are
different in this regard.
Best regards,
Andrew
KavaSoft
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden