simple regex with NSTask
simple regex with NSTask
- Subject: simple regex with NSTask
- From: Al Skipp <email@hidden>
- Date: Mon, 12 Feb 2007 15:06:52 +0000
I'm attempting to get a simple regex working by using NSTask with a
shell script, though without much joy. The regex removes characters I
don't want included in file names - the problem is that all
paragraphs are extracted and the returned string is only one line of
text.
The details of the problem are outlined below, any suggestions most
appreciated.
It works fine when called through Applescript:
***********************************
Applescript:
set testString to "just::;;
testing,,...
///??now"
set resultString to text of (do shell script "echo " & quoted form of
testString & "| sed -e 's/[/,;:.\\?]//g'")
resultString is:
"just
testing
now"
***********************************
However when I attempt to do the same with a shell script called with
NSTask, the paragraphs are removed:
Shell script:
#! /bin/sh
echo $1 | sed -e 's/[/,;:.\?]//g'
result is:
"just testing now"
***********************************
An extract of the objective-C code is below
NSString *testString = @"just???\ntesting...\n:::::now"];
NSArray *arg = [NSArray arrayWithObject:testString];
NSTask *task = [[[NSTask alloc]init]autorelease];
[task setLaunchPath:scriptPath];
[task setArguments:arg];
NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file = [pipe fileHandleForReading];
[task launch];
NSData *data = [file readDataToEndOfFile];
NSString *newString = [[[NSString alloc] initWithData: data encoding:
NSUTF8StringEncoding]autorelease];
NSLog(@"verified string, %@", newString);
_______________________________________________
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