Re: Dumping input to NSTask
Re: Dumping input to NSTask
- Subject: Re: Dumping input to NSTask
- From: John Timmer <email@hidden>
- Date: Thu, 15 Jul 2004 08:47:39 -0400
Louis -
Thanks so much for your help. This indeed did the trick, and was
substantially faster than writing files in /tmp. 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.
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]];
Oh well, I'll know who to write if this breaks in Tiger....
Cheers,
John
>
>
I hope that there is a better way to accomplish it, but one (very
>
unsupported) workaround would be to do this after you finish writing
>
all of your data to the standard input pipe:
>
>
(you will need to #include "unistd.h")
>
>
NSFileHandle *input = [[yourTask standardInput] fileHandleForWriting];
>
close([input fileDescriptor]);
>
[input setValue:[NSNumber numberWithUnsignedShort:1] forKey:@"_flags"];
>
>
This manually closes the fileDescriptor of the NSFileHandle, and then
>
changes the flag that NSFileHandle uses to determine if it is
>
supposed to close the file descriptor when the NSConcreteFileHandle
>
instance is dealloc'ed.
>
Hope that helps,
>
>
Louis
>
_______________________________________________
This mind intentionally left blank
_______________________________________________
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.