one NSPipe, multiple NSTasks?
one NSPipe, multiple NSTasks?
- Subject: one NSPipe, multiple NSTasks?
- From: beamsplitter <email@hidden>
- Date: Sun, 23 Mar 2003 23:41:22 -0500
I'd like to use one NSPipe instance for multiple successive NSTasks.
I've tried this but can't get it to work:
NSPipe *myPipe = [[NSPipe alloc] init];
NSTask *myTask = [[[NSTask alloc] init] autorelease];
NSTask *myNextTask = [[[NSTask alloc] init] autorelease];
[myTask setStandardOutput: myPipe];
[myTask setStandardError: myPipe];
[[NSNotificationCenter defaultCenter] addObserver: self selector:
@selector(getPipeOutput:) name: NSFileHandleReadCompletionNotification
object: [myPipe fileHandleForReading]];
[[myPipe fileHandleForReading] readInBackgroundAndNotify];
[myTask launchTask];
// ...
// task has terminated
[[NSNotificationCenter defaultCenter] removeObserver: self name:
NSFileHandleReadCompletionNotification object: [myPipe
fileHandleForReading]];
// ...
[myNextTask setStandardOutput: myPipe];
[myNextTask setStandardError: myPipe];
[[NSNotificationCenter defaultCenter] addObserver: self selector:
@selector(getPipeOutput:) name: NSFileHandleReadCompletionNotification
object: [myPipe fileHandleForReading]];
[[myPipe fileHandleForReading] readInBackgroundAndNotify];
[myNextTask launchTask];
// ...etc
The second pair of setStandard methods cause an exception: "Exception
raised during posting of notification. Ignored. exception: ***
-[NSConcreteFileHandle fileDescriptor]: Bad file descriptor"
Can anyone point out my mistake?
Thanks,
Scott
_______________________________________________
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.