Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTask interactive question



I have an NSTask which is a Ruby interactive script. The Ruby script just
loops on standard input, like this:

while (s = gets)
  puts gk.crunch(s) # never mind what that does
  $stdout.flush
end

I'm launching this NSTask and then I'm repeatedly sending input at it and
retrieving the output, all in a single routine, without using notifications,
like this:

NSString* input = [NSString stringWithFormat: @"%@\n", s];
NSFileHandle* fh = [[task standardInput] fileHandleForWriting];
[fh writeData:[input dataUsingEncoding: NSMacOSRomanStringEncoding]];
NSFileHandle* fh2 = [[task standardOutput] fileHandleForReading];
NSString* output = [[[NSString alloc] initWithData: [fh2 availableData]
   encoding: NSUTF8StringEncoding] autorelease];

I'm just doing that over and over again, supplying input and retrieving
output in a single step. It's working fine. My question is: even though it's
working, am I in fact cruising for a bruising? Must I instead use the more
complicated readInBackgroundAndNotify architecture? m.

-- 
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>



_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.