Skip navigation.
 
mlRe: Non-ASCII NSTask arguments
FROM : Steve Christensen
DATE : Tue Aug 22 20:43:29 2006

On Aug 22, 2006, at 10:04 AM, Martin wrote:

> How am I supposed to create and launch an NSTask when one of its 
> arguments is a file path containing non-ASCII characters ?
>
> The follwing code doesn't work (du says the file doesn't exist)
> - (IBAction)test:(id)sender
> {
>         NSTask *aTask = [[NSTask alloc] init];
>         NSMutableArray *args = [NSMutableArray array];
>
>         [args addObject:@"/Users/martin/יאשח.txt"];
>         [aTask setLaunchPath:@"/usr/bin/du"];
>         [aTask setArguments:args];
>         [aTask launch];
> }
>
> I've tried many different things and made numerous tests (using 
> NSString stringWith..., logging the result with 
> fileSystemRepresentation, etc...) and the only thing that works is :
> [args addObject:[NSString stringWithUTF8String:"/Users/martin/
> יאשח.txt"]];
>
> Ok, that works if I actually hard-type the file path in my source 
> code. But the file path I already have is a NSString coming from a 
> drag & drop operation. But unfortunately, the following code 
> doesn't work !
> [args addObject:[NSString stringWithUTF8String:[myFilePath 
> UTF8String]]];


You said above, "the file path I already have is a NSString coming 
from a drag & drop operation." So why don't you just use the string 
as-is?

    [args addObject:myFilePath]?

Your code is taking the unicode drag & drop string, converting it to 
utf8, and passing that back in to create a new unicode string. That 
seems a bit roundabout, unless I'm misunderstanding something.

steve

Related mailsAuthorDate
mlNon-ASCII NSTask arguments Martin Aug 22, 19:04
mlRe: Non-ASCII NSTask arguments Nick Zitzmann Aug 22, 19:36
mlRe: Non-ASCII NSTask arguments Steve Christensen Aug 22, 20:43
mlRe: Non-ASCII NSTask arguments Nir Soffer Aug 24, 13:09
mlRe: Non-ASCII NSTask arguments Andrew Farmer Aug 24, 18:09
mlRe: Non-ASCII NSTask arguments Nir Soffer Aug 25, 01:02