Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > asynchronous read on a NSFileHandle..?

asynchronous read on a NSFileHandle..?
Thread Tools
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
Feb 28, 2001, 10:26 PM
 
I've setup a test where I run a command-line app that needs lots of attention, so to speak. It should (does) have lots of output but I can't seem to get any. Its interactive so a one-shot run isn't possible but if it were I could do that.

I have:
Code:
[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(dataRead name: NSFileHandleReadToEndOfFileCompletionNotification object: outputFileHandle];
before I launch the task. And, in my dataRead method I have NSLog(@"got something"); for now. Is that right?

Im just a confused newbie, I guess. Any ideas or help would be great!

Thanks in advance!
     
IamBob  (op)
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
Mar 1, 2001, 09:05 AM
 
forget to add [outputFileHandle readInBackgroundAndNotify]; into that code snippet.

..and I should've disabled smilies.
     
IamBob  (op)
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
Mar 1, 2001, 11:41 AM
 
Nevermind. I've figured it out (basically).

It goes something like:
Code:
- (void)runTask:(NSString *)myTask; { //..minus setup. [[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(dataIsAvailable:) name:NSFileHandleDataAvailableNotification object: outputFileHandle]; [task launch]; [outputFileHandle waitForDataInBackgroundAndNotify]; } - (void)dataIsAvailable:(NSNotification *) aNotif { //get the availableData from the NSFileHandle and do stuff with it }
;

Great!
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:29 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2