• 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
NSTask & NSPipe
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTask & NSPipe


  • Subject: NSTask & NSPipe
  • From: Darin Duphorne <email@hidden>
  • Date: Wed, 27 Jun 2001 14:54:08 -0500

Thanks to several folks, my code now works and is below; but, it only works if the returned text is fairly short. It doesn't work for longer strings. Is this because I didn't use the NotificationCenter? Any ideas? By the way, I have replaced the "ls -al" command with a text tool for returning bible verses. This is the purpose of the exercise.

#import "brsWrapper.h"

@implementation brsWrapper

- (IBAction)get:(id)sender
{
NSTask *theTask=[[NSTask alloc] init];
NSMutableArray *theArgs=[NSMutableArray array];
NSPipe *thePipe=[NSPipe pipe];
NSFileHandle *pipeOutput=[thePipe fileHandleForReading];
NSData *outData=nil;
NSString *theString=nil;

[theArgs addObject:[brsEntryField stringValue]];
[theTask setLaunchPath:@"/usr/bin/bible"];
[theTask setArguments:theArgs];
[theTask setStandardOutput:thePipe];

[theTask launch];

while ((outData=[pipeOutput availableData]) && ([outData length]))
{
theString=[[NSString alloc] initWithData:outData encoding:NSASCIIStringEncoding];
[brsDisplayField setString:[[brsDisplayField stringValue] stringByAppendingString:theString]];
[theString release];
}

[theTask release];


}

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *) theApplication
{
return YES;
}

- (void)awakeFromNib
{
[brs makeKeyAndOrderFront:nil];
}

@end


  • Prev by Date: Re: autoreleasing NSBezierPath object
  • Next by Date: NSImageView interpolation
  • Previous by thread: Re: Frantic and Frustrated {Additional to previous}
  • Next by thread: Re: NSTask & NSPipe
  • Index(es):
    • Date
    • Thread