• 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
Re: NSTask - grep
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTask - grep


  • Subject: Re: NSTask - grep
  • From: Andreas Monitzer <email@hidden>
  • Date: Tue, 10 Jul 2001 01:19:12 +0200

On Tuesday, July 10, 2001, at 12:00 , Kent Glenn wrote:

I'm having some problems getting grep to work with NSTask. I've gotten NSTask to work with some of the examples for "ls" on this list. I have even gotten it to work partially with "grep".

I want to grep for a pattern in a directory, and it's sub-directories. If I use a file name instead of the wildcard '*', then it will work. When I try to use the wildcard, I get this message: "grep: /Users/kglenn/*: No such file or directory". If I execute the same command from Terminal, it works perfectly. I thought maybe I had to escape the '*' at first, but that didn't work.

NSTask *myTask=[[NSTask alloc] init];

[myTask setLaunchPath:@"/usr/bin/grep"];
[myTask setArguments:[NSArray arrayWithObjects:@"-r",@"somestring",@"/Users/kglenn/*",nil]];
[myTask launch];
[myTask release];


I know it's something stupid I'm doing. Thanks in advance for the help.

The shell expands '*' before sending the command to grep. That means you have to expand it yourself for grep (using NSDirectoryEnumerator):

NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager]
enumeratorAtPath:@"/Sales/Reports"];
NSMutableArray *arguments=[[NSMutableArray alloc] initWithObjects:@"-r",@"
somestring",nil];
NSTask *myTask=[[NSTask alloc] init];

NSString *pname;
while (pname = [direnum nextObject]) {
[arguments addObject:pname];
}

[myTask setLaunchPath:@"/usr/bin/grep"];
[myTask setArguments:arguments];
[myTask launch];

[myTask release];
[arguments release];

btw there might be a more efficient way (a C-API instead of grep).

andy
--
Discussion forthcoming.


  • Follow-Ups:
    • Re: NSTask - grep
      • From: Art Isbell <email@hidden>
    • Re: NSTask - grep
      • From: Jean-François Veillette <email@hidden>
References: 
 >NSTask - grep (From: Kent Glenn <email@hidden>)

  • Prev by Date: Joystick Inputs in Cococa Apps.
  • Next by Date: Re: Title bar for Sheets
  • Previous by thread: NSTask - grep
  • Next by thread: Re: NSTask - grep
  • Index(es):
    • Date
    • Thread