cocoa - How to gradually retrieve data from NSTask? -


I am working on a GUI (cocoa) for a command line tool which makes it more accessible to people. Despite this being a GUI, I would like to display the output in NSTextView. The problem is that the output is large and the analyzed device can take hours / days. Generally, when working with NSTK and NSPP, the output is displayed after the complete expiry (which may take a long time). What I want to do is divide the output and show it slowly (for example, updating every minute).

So far, I have kept data processing in a separate thread:

  [NSThread detachNewThreadSelector: @selector (to process) to toggle: self-with object: Raxmal Handel]; - (zero) Process data: (ID) Sender {NSAutoreleasePool * pool = [[NSAUTOreappul Alok] IIT]; NSString * startString = [result string]; NSString * newString = [[NSString alloc] initWithData: [raxmlHandle readDataToEndOfFile] Encoding: NSASCIIStringEncoding]; [Result setstring: [start string stringbapping string: new string]]; [Startstress release]; [New string release]; [Bridge release]; }  

All this is still a magic on me and I do not know exactly how to deal with this challenge.

Do you have any suggestions or suggestions?

Thank you!

After the

you need to use any information provided by NSFileHandle .

First of all,

  [[NSNotificationCenter defaultCenter] addObserver: Self selector: @selector (outputReceived :) Name: NSFileHandleReadCompletionNotification Object: Zero] Form of a Supervisor Add in;  

Then, a task, to prepare a call handle of a pipe file, and launch the work.

  NSTask * task = [[NSTask alloc] in this]; [Work Set Lockpath: ...]; NSPipe * Pipe = [NSPipe pipe]; [Work Setstodo Output: Pipe]; [Task setder error: pipe]; // This information causes notification when available. [[Pipe filehousingForcing] readInBackgroundAndNotify]; [Launch the task]; To get the data actually, you need to define a method  
  - (zero) outputReceived: (NSNotification *) notification { NSFileHandle * FH = [information object]; // It may be nice to check that this file handle is the one you want to read ... NSData * d = [[aNotification userInfo] objectForKey: @ "NSFileHandleNotificationDataItem"]; ... do something with the data ...}  

You want to read to understand what is happening.


Comments