Re: NSString encoding and perl script encoding
Re: NSString encoding and perl script encoding
- Subject: Re: NSString encoding and perl script encoding
- From: Sherm Pendley <email@hidden>
- Date: Thu, 1 Feb 2007 13:33:10 -0500
On Feb 1, 2007, at 12:45 PM, David Brennan wrote:
I am doing nothing with the perl script yet. I plan to use perl, to
apply regular expressions to the text from PDF's, so I want to use
unicode. I tried to use the encoding NSUnicodeStringEncoding, but the
returned string was not correct. When I use the NSUTF8StringEncoding
encoding, I lose some of the text, because converting the NSData from
the pipe to NSString returns nil sometimes.
I don't know why this is not working, I would be very grateful of
any help.
Since you're waiting until the Perl task completes before reading
*any* of its output, you're probably running out of buffer space.
That's got nothing to do with how your Perl code is written.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getData:)
name: NSFileHandleReadCompletionNotification
object: readHandle];
[[[task standardOutput] fileHandleForReading]
readInBackgroundAndNotify];
[task launch];
inputString = inString;
[NSThread detachNewThreadSelector:@selector(threadRunFuntion:)
toTarget:self withObject:nil];
[task waitUntilExit];
Note that -waitUntilExit blocks the run loop, so no notifications
will be sent until the task exits. To get the notifications you asked
for above, you need to use -readInBackgroundAndNotify, and *don't*
call -waitUntilExit - let the run loop run, so you get the
notifications.
If you want to just read all of the task's output, instead of reading
it a chunk at a time, you could register for
NSFileHandleReadToEndOfFileCompletionNotification and use -
readToEndOfFileInBackgroundAndNotify instead.
sherm--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden