issues with NSTask/NSPipe
issues with NSTask/NSPipe
- Subject: issues with NSTask/NSPipe
- From: Jim Puls <email@hidden>
- Date: Sun, 17 Mar 2002 19:13:27 -0600
So, say, for example, that one was going to write a program to interface
with a command shell, using NSTask to run the shell and NSPipe for I/O.
How would one go about reading and writing from a program that expects
interactivity? I've pasted in what I've tried, but it's obviously the
wrong thing. I would be highly appreciative if somebody could disperse
the cloud of ignorance that has settled in around my head.
- (IBAction)runCommand:(id)sender
{
NSString *thePath = [pathField stringValue];
NSString *mainOutput = [NSString string];
NSString *temp;
NSData *outData = [[thePath stringByAppendingString:@"\n"]
dataUsingEncoding:NSASCIIStringEncoding];
NSData *inData = nil;
[mainIn write
Data:outData];
while ((inData = [mainOut availableData]) && [inData length])
{
temp = [[NSString alloc] initWith
Data:inData
encoding:NSASCIIStringEncoding];
mainOutput = [mainOutput stringByAppendingString:temp];
[temp release];
}
[outputView setString:mainOutput];
}
- (void)awakeFromNib
{
mainTask = [[NSTask alloc] init];
pipeOut = [NSPipe pipe];
pipeIn = [NSPipe pipe];
mainOut = [pipeOut fileHandleForReading];
mainIn = [pipeIn fileHandleForWriting];
[mainTask setStandardOutput:pipeOut];
[mainTask setStandardInput:pipeIn];
[mainTask setLaunchPath:@"/bin/bash"];
[mainTask launch];
}
--
( jim |
http://www.nondifferentiable.com)
( aim | parkrigid)
( jabber | email@hidden)
( icq | 4666819)
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.