Launching Terminal Application
Launching Terminal Application
- Subject: Launching Terminal Application
- From: mw <email@hidden>
- Date: Fri, 29 Nov 2002 23:49:33 -0500
Hey all,
I based this little bit of "sample code" off of an Apple code example in the
dev docs. It is just supposed to load up 'top' from the command-line, and
then pipe the output back into the cocoa program and display it in an
NSTextView. But it doesn't work. I get an error that says "Error opening
terminal: unknown." I have no idea what I am doing wrong. Here is the code.
#import "AppController.h"
#import <Foundation/Foundation.h>
@implementation AppController
- (IBAction)runPipe:(id)sender
{
NSTask *taskCalledTop = [[NSTask alloc] init];
NSPipe *readPipeToTop = [NSPipe pipe];
NSFileHandle *readHandleToTop = [readPipeToTop fileHandleForReading];
NSData *dataFromTop = nil;
[taskCalledTop setStandardOutput:readPipeToTop];
[taskCalledTop setLaunchPath:@"/usr/bin/top"];
[taskCalledTop setArguments:[NSArray arrayWithObject:@"ln0"]];
[taskCalledTop launch];
dataFromTop = [readHandleToTop availableData];
[self dataToTextView:dataFromTop];
[taskCalledTop release];
}
- (void)dataToTextView:(NSData *)data
{
[textView insertText:data];
}
@end
Btw, the error is being shown after the line [taskCalledTop launch] is
executed. Any ideas?
TIA, mw
_______________________________________________
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.