Re: NSTask and NSPipe
Re: NSTask and NSPipe
- Subject: Re: NSTask and NSPipe
- From: Eric Clements <email@hidden>
- Date: Wed, 27 Jun 2001 07:24:22 -0400
Here is some code I wrote as a general utility function.... Feel free to
use or change.
NSString *launchTaskGetOutput( NSString *exec, NSArray *args )
{
NSTask *pipeTask = [NSTask new];
NSPipe *newPipe = [NSPipe pipe];
NSFileHandle *readHandle = [newPipe fileHandleForReading];
NSString *returnValue;
[pipeTask setStandardOutput:newPipe]; // write handle is closed to
this process
[pipeTask setLaunchPath:exec];
[pipeTask setArguments:args];
[pipeTask launch];
[pipeTask waitUntilExit]; // Wait until the task finishes
returnValue = [[NSString alloc] initWith
Data:[readHandle
availableData] encoding:NSASCIIStringEncoding];
[pipeTask release];
return returnValue;
}
On Wednesday, June 27, 2001, at 04:46 AM, cocoa-dev-
email@hidden wrote:
Message: 10
Date: Tue, 26 Jun 2001 16:13:14 -0500
From: Darin Duphorne <email@hidden>
To: email@hidden
Subject: NSTask and NSPipe
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?
Thanks