Re: Dumping input to NSTask
Re: Dumping input to NSTask
- Subject: Re: Dumping input to NSTask
- From: "Louis C. Sacha" <email@hidden>
- Date: Thu, 15 Jul 2004 15:12:22 -0700
Hello...
I would have thought that
sending the fileHandle a "closeFile" would have done the same thing without
making assumptions about the underlying implementation, but Cocoa's full of
interesting surprises like this.
You're right, using closeFile on the handle actually _should_ work
correctly (instead of using the work around code that I posted to do
it manually).
The thing is, I have one app where using closeFile causes the
NSConcreteFileHandle to raise an exception later during dealloc,
although the code in that application doesn't seem to be any
different from several other apps using NSTask where it works
correctly. When I replace that call with the workaround code the
exception doesn't occur, although I haven't had a chance to figure
out why at this point. I'm doing the opposite of unit testing,
making small changes to some test code in a framework and then seeing
if it breaks the applications :)
It's very possible that there is some related bug in that particular
application which is causing the problem, so I would recommend using
fileClose on the input pipe's file handle if it works in your current
code, since that would be a much better way to do things.
Along those lines, I found it amusing that this works:
theResults = [[[NSString alloc] initWithData: taskResponseData
encoding: NSUTF8StringEncoding]
autorelease];
But this doesn't:
theResults = [NSString stringWithUTF8String: [taskResponseData bytes]];
Using the initWith
Data:encoding: method is much better since it uses
the length provided by the NSData object, where as using the bytes
directly as a char* or unichar* string will cause problems when the
string is prematurely or improperly terminated (which happens quite
often when you are getting the bytes indirectly from some other
source).
Hope that helps...
Louis
_______________________________________________
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.