• 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
Re: Being notified of changes to a file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Being notified of changes to a file


  • Subject: Re: Being notified of changes to a file
  • From: Yann Disser <email@hidden>
  • Date: Tue, 22 Jul 2008 12:08:11 +0200

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 (email@hidden)

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:
This email sent to email@hidden


References: 
 >Being notified of changes to a file (From: Yann Disser <email@hidden>)
 >Re: Being notified of changes to a file (From: Jens Alfke <email@hidden>)
 >Re: Being notified of changes to a file (From: Yann Disser <email@hidden>)
 >Re: Being notified of changes to a file (From: "Finlay Dobbie" <email@hidden>)

  • Prev by Date: SBApplication error with iTunes 7.7
  • Next by Date: Re: NSEntityDescription random crash
  • Previous by thread: Re: Being notified of changes to a file
  • Next by thread: Re: Being notified of changes to a file
  • Index(es):
    • Date
    • Thread