• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
simple regex with NSTask
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: simple regex with NSTask
      • From: Nathan Day <email@hidden>
  • Prev by Date: Printing crash
  • Next by Date: Seeking a contractor in the western Massachusetts area
  • Previous by thread: Re: Printing crash
  • Next by thread: Re: simple regex with NSTask
  • Index(es):
    • Date
    • Thread