Re: More on NSTask and output to NSTextView
Re: More on NSTask and output to NSTextView
- Subject: Re: More on NSTask and output to NSTextView
- From: p3consulting <email@hidden>
- Date: Sun, 6 Jun 2004 09:48:02 +0200
Le juin 5, 2004, ` 13:47, Koen van der Drift a icrit :
>
Hi,
>
>
Thanks to all the good suggestions on the list I am now using an
>
NSTask to launch a commandline program in a GUI. It all works very
>
nice except displaying the output from the program in an NSTextView is
>
displayed in chunks. After searching the archives it seems that this
>
is caused by the NSTask - NSPipe - NSFileHandle combination that does
>
some buffering. This has been discussed before and the general
>
suggestion to prevent this is to use readInBackgroundAndNotify on the
>
NSFileHandle. Here is a snippet:
>
>
.....
>
[startButton setTitle: @"Running"];
>
[startButton setEnabled:NO];
>
>
pipe = [[NSPipe alloc] init];
>
>
myTask = [[NSTask alloc] init];
>
[myTask setLaunchPath:[[NSBundle mainBundle]
>
pathForResource:@"atask" ofType:nil]];
>
[myTask setArguments:args];
>
Try adding here
NSMutableDictionary *defaultEnv = [[NSMutableDictionary alloc]
initWithDictionary:[[NSProcessInfo processInfo] environment]] ;
[defaultEnv setObject:@"YES" forKey:@"NSUnbufferedIO"] ;
[myTask setEnvironment:defaultEnv] ;
>
[myTask setStandardOutput:pipe];
>
handle = [pipe fileHandleForReading];
>
>
[[NSNotificationCenter defaultCenter] addObserver:self
>
selector:@selector(getData:)
>
>
name:NSFileHandleReadCompletionNotification
>
object:handle];
>
>
[handle readInBackgroundAndNotify];
>
>
[myTask launch];
>
>
[pipe release];
>
Pascal Pochet
email@hidden
----------------------------------
PGP
KeyID: 0x208C5DBF
Fingerprint: 9BFB 245C 5BFE 7F1D 64B7 C473 ABB3 4E83 208C 5DBF
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.