• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSTask interactive question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTask interactive question


  • Subject: NSTask interactive question
  • From: Matt Neuburg <email@hidden>
  • Date: Wed, 29 Nov 2006 12:09:33 -0800
  • Thread-topic: 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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSTask interactive question
      • From: "Shawn Erickson" <email@hidden>
  • Prev by Date: Chinese character handwriting recognition
  • Next by Date: Re: NSTask interactive question
  • Previous by thread: Chinese character handwriting recognition
  • Next by thread: Re: NSTask interactive question
  • Index(es):
    • Date
    • Thread