• 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: David Remahl <email@hidden>
  • Date: Wed, 27 Jun 2001 07:47:15 +0200

There are several examples on this online. For example on cocoadevcentral. If you cant get it to work, post some code and we'll help you spot the error.

I might as well write a few lines outlining what you need to do:

NSTask* lsTask = [[NSTask alloc] init];
NSPipe* pipe = [NSPipe pipe];
NSFileHandle* fh = NULL;

[lsTask setLaunchPath:@"/bin/ls"];
[lsTask setStandardOutput:pipe];
[lsTask setCurrentDirectoryPath:[textFieldWithDirectoryToList stringValue]];
[lsTask setArguments:[NSArray arrayWithObject:@"-al"]];
[lsTask launch];

fh = [pipe fileHandleForReading];

[textFieldWithListingOutput setStringValue:[[[NSString alloc] initWithData:[fh readDataToEndOfFile] encoding:NSASCIIStringEncoding] autorelease]];

There you go...I typed it directly into the email, so you may have to make some adjustments...Good luck!

/ david

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?


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

  • Prev by Date: Re: Reading plists
  • Next by Date: Image Manipulation
  • Previous by thread: NSTask and NSPipe
  • Next by thread: Re: NSTask and NSPipe
  • Index(es):
    • Date
    • Thread