Re: NSTask vs. special characters
Re: NSTask vs. special characters
- Subject: Re: NSTask vs. special characters
- From: Pierre Bernard <email@hidden>
- Date: Sun, 29 Apr 2007 23:51:23 +0200
Got it to work:
NSString *filePath = [[destPath shellSafeString] fileSystemString];
where:
- (NSString*) shellSafeString
{
NSMutableString *string = [self mutableCopy];
// Unsafe
[string replaceOccurrencesOfString:@"\\" withString:@"\\\\"
options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"?" withString:@"\\?"
options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"*" withString:@"\\*"
options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"'" withString:@"\\'"
options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"`" withString:@"\\`"
options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"$" withString:@"\\$"
options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"&" withString:@"\\&"
options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"|" withString:@"\\|"
options:NSLiteralSearch range:NSMakeRange(0, [string length])];
// White space
[string replaceOccurrencesOfString:@" " withString:@"\\ "
options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"\a" withString:@"\\a"
options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"\t" withString:@"\\t"
options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"\n" withString:@"\\n"
options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"\f" withString:@"\\f"
options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"\r" withString:@"\\r"
options:NSLiteralSearch range:NSMakeRange(0, [string length])];
return string;
}
- (NSString*) fileSystemString
{
NSString *string = [NSString stringWithFormat:@"%s", [self
fileSystemRepresentation]];
return string;
}
Pierre Bernard
Houdah Software s.à r.l.
On Apr 29, 2007, at 7:18 PM, Pierre Bernard wrote:
Hi!
How can I get NSTask to work binary and argument paths containing
special characters like French accents?
TIA for your help.
Best,
Pierre
---
Pierre Bernard
http://www.bernard-web.com/pierre
http://www.houdah.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
- - -
Houdah Software s. à r. l.
http://www.houdah.com
HoudahGeo: One-stop photo geocoding
HoudahSpot: Powerful Spotlight frontend
---
Pierre Bernard
http://www.bernard-web.com/pierre
http://www.houdah.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden