Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: NSTask with non-ASCII paths
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTask with non-ASCII paths



Hi Andrew,

try to do it this way:

- (int) performSipsTransformation: (NSMutableArray *) arguments {
         NSString *parentPath = [absolutePath
stringByDeletingLastPathComponent];
         NSString *name = [absolutePath lastPathComponent];

         [arguments addObject: [name fileSystemRepresentation]];

NSTask *sipsTask = [[[NSTask alloc] init] autorelease];
[sipsTask setLaunchPath: @"/usr/bin/sips"];
[sipsTask setCurrentDirectoryPath: [parentPath fileSystemRepresentation]];
[sipsTask setArguments: arguments];
[sipsTask launch];
[sipsTask waitUntilExit];
return [sipsTask terminationStatus];
}


Does it work as expected?

Bye,

Severin Kurpiers
Verek Ltd.

On 7 Jan 2005 Andrew Zamler-Carhart wrote:

Message: 10
Date: Fri, 7 Jan 2005 23:45:12 +0000
From: Andrew Zamler-Carhart <email@hidden>
Subject: NSTask with non-ASCII paths
To: email@hidden
Message-ID: <email@hidden>
Content-Type: text/plain; charset=UTF-8; format=flowed

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


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.