Re: NSTask and NSPipe
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]
initWith
Data:[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?