• 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
issues with NSTask/NSPipe
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 writeData:outData];

while ((inData = [mainOut availableData]) && [inData length])
{
temp = [[NSString alloc] initWithData: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.

  • Prev by Date: Default Button Cells
  • Next by Date: Re: Some good docs viewer?
  • Previous by thread: Re: Default Button Cells
  • Next by thread: Re: issues with NSTask/NSPipe
  • Index(es):
    • Date
    • Thread