Re: one NSPipe, multiple NSTasks?
Re: one NSPipe, multiple NSTasks?
- Subject: Re: one NSPipe, multiple NSTasks?
- From: Marcel Weiher <email@hidden>
- Date: Tue, 25 Mar 2003 08:27:47 +0100
On Tuesday, March 25, 2003, at 01:36 Uhr, beamsplitter wrote:
I'd like to use one NSPipe instance for multiple successive NSTasks.
Why?
Because it's cleaner and easier.
Well, it isn't actually easier because it doesn't work. I also don't
see in which way it could be considered cleaner. It is much cleaner to
always pair the NSPipe/NSTask.
[code snipped]
Can anyone point out my mistake?
Yes: wanting to reuse a pipe for successive tasks. The sub-task
will close the pipe and then it is gone (that is why the
file-descriptor is "bad").
From the documentation:
"+ (id)pipe
Returns an NSPipe that's been sent autorelease. Because the returned
object will be deallocated at the end of the current loop, retain the
object or, better yet, use the init method if you intend to keep the
object beyond that point."
Yes, and? This (a) says something about the NSPipe object, not the
file-handle associated with it (well if it is deallocated, it will
probably also be closed if it isn't already).
and
"- (NSFileHandle *)fileHandleForReading
...You don't need to send closeFile to this object or explicitly
release the object after you're finished using it. The descriptor
represented by this object is deleted, and the object itself is
automatically deallocated when the NSPipe is deallocated."
Doesn't this contradict what you wrote about the sub-task closing the
pipe?
Not in the least bit. It means that you don't *have* to close it. It
doesn't mean that you (or somebody else) *can't* close it.
If you do:
close( [myPipe fileHandleForReading] );
then the file-handle is closed.
If so, is there an error in the documentation?
No. You are just misinterpreting it.
I used the init method expressly so I could hang onto the pipe
object, and all the code below "// task has terminated" is before the
NSTask has been released.
The issue is not when the NSTask is released. The NSTask is just an
object to keep track of the Unix process. The issue is when the actual
Unix process has terminated (or rather, what this Unix process does to
its open files).
So, it seems like both the task and the pipe should still be around...
No. Once again, don't confuse the Cocoa wrappers with the actual
entities they are wrapping. If a Unix process exit()s or is killed,
then it will be gone, no matter how often you've retain the NSTask that
was used to create it.
Regards,
Marcel
--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
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.