RE: NSTask
RE: NSTask
- Subject: RE: NSTask
- From: "Sprague, Graham" <email@hidden>
- Date: Thu, 28 Jun 2001 08:50:30 -0400
Ok,
I got the results to go into a text field(resultList). How do I clear the
text field before the next search? I tried setting it to nil but that won't
work. I think I must be missing something very simple. Could anyone help?
Here's is my code...
#import "locateWrapper.h"
@implementation locateWrapper
- (IBAction)displayFilePath:(id)sender
{
}
- (IBAction)locate:(id)sender
{
NSPipe *thePipe=[NSPipe pipe];
NSFileHandle *pipeOutput=[thePipe fileHandleForReading];
NSData *outData=nil;
NSString *theString=nil;
[goButton setTitle:@"Searching"];
[goButton setEnabled:NO];
locate=[[NSTask alloc] init];
[locate setLaunchPath:@"/usr/bin/locate"];
// I thought this might work but no dice.
//[resultList setStringValue:nil];
[locate setArguments:[NSArray arrayWithObject:[criteria stringValue]]];
[locate setStandardOutput:thePipe];
[locate launch];
// Wait until the task finishes
//[locate waitUntilExit];
while ((outData=[pipeOutput availableData]) && ([outData length]))
{
theString=[[NSString alloc] initWith
Data:outData
encoding:NSASCIIStringEncoding];
[resultList setStringValue:[[resultList stringValue]
stringByAppendingString:theString]];
[theString release];
}
}
-(id)init {
self = [super init];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(finishedLocate:)name:NSTaskDidTerminateNotification
object:nil];
locate = nil;
return self;
}
-(void)finishedLocate:(NSNotification *)aNotification {
[goButton setTitle:@"Go"];
[goButton setEnabled:YES];
[locate release];
locate=nil;
}
-(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication
*)theApplication {
return YES;
}
- (IBAction)showInFinder:(id)sender
{
}
@end