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

Re: NSTask and NSPipe


  • Subject: Re: NSTask and NSPipe
  • From: Jorge Salvador Caffarena <email@hidden>
  • Date: Wed, 27 Jun 2001 11:29:40 +0200

Can anyone provide me a simple example of how to pipe standardoutput from a NSTask to a textfield on a window? I can't for the life of me get it to work. Perhaps a simple example of calling ls -al and displaying in a tableview or textfield?

Here you are, this works O.K. (tested):

NSTask *theTask = [[NSTask alloc] init];
NSMutableArray *theArgs = [NSMutableArray array];
NSPipe *thePipte = [NSPipe pipe];
NSFileHandle *pipeOutput = [thePipe fileHandleForReading];
NSData *outData = nil;
NSString *theString = nil;

[theArgs addObject:@"-al"];
[theArgs addObject:NSHomeDirectory()];
[theTask setLaunchPath:@"/bin/ls"];
[theTask setArguments:theArgs];
[theTask setStandardOutput:thePipe];

[theTask launch];

while ((outData = [pipeOutput availableData]) && ([outData length]) {
theString = [[NSString alloc] initWithData:outData
encoding:NSASCIIStringEncoding];

[theTextField setString:[[theTextField stringValue] stringByAppendingString:theString]];

[theString release];
}

[theTask release];

Jorge Salvador Caffarena
http://homepage.mac.com/eevyl/


References: 
 >NSTask and NSPipe (From: Darin Duphorne <email@hidden>)

  • Prev by Date: Re: Disclosure triangle ?
  • Next by Date: Re: Communicate with pipe and AuthorizationExecuteWithPrivileges
  • Previous by thread: Re: NSTask and NSPipe
  • Next by thread: Re: NSTask and NSPipe
  • Index(es):
    • Date
    • Thread