Ok, thank you all guys! I got it working somehow ^^

Here is my code (if anyone is interested - I am probably doing a lot of crazy things, please correct me):

#import <Cocoa/Cocoa.h>

@interface Observer : NSObject
{}
- (void) outputStuff:(NSNotification*)aNotification;
@end

@implementation Observer
- (void) outputStuff:(NSNotification*)aNotification
{
  id obj = [aNotification object];
NSData* data = [[aNotification userInfo] objectForKey:NSFileHandleNotificationDataItem];
  if(data && [data length] > 0)
  {
NSString* str = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
    NSLog(@" -- outputting stuff -- ");
    NSLog(str);
    [obj readInBackgroundAndNotify];
  }
}
@end

int main(int argc, char *argv[])
{
  Observer* obs = [[Observer alloc] retain];

  NSTask* task = [[NSTask alloc] init];
  [task setLaunchPath:@"numbers.rb"];

  NSPipe* output = [NSPipe pipe];
  [task setStandardOutput:output];

  NSFileHandle* file = [output fileHandleForReading];

  [[NSNotificationCenter defaultCenter] addObserver:obs
selector:@selector(outputStuff:) name:NSFileHandleReadCompletionNotification
                                             object:file];
  [file readInBackgroundAndNotify];
  [task launch];

  return NSApplicationMain(argc,  (const char **) argv);
}

And here is the ruby script:

#!/usr/bin/env ruby
STDOUT.sync = true
100.times do |i|
  puts i
  sleep 0.05
end

Thanks again,
Yann
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please 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/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to