Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Launching Terminal Application



If you run top manually just as you are running it here (top ln0) you'll
see it still goes into interactive mode as it's ignoring your argument.
Interactive mode requires a terminal with which top can communicate, and
a pipe isn't one of them, hence the error.
Instead, try

[taskCalledTop setArguments:[NSArray arrayWithObject:@"-l1"]];

to get one sample from top, without requiring a terminal top knows.

Bryan


On Nov 29, 2002 23:49, mw stated:
> 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.

References: 
 >Launching Terminal Application (From: mw <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.