Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTask waitForDataInBackgroundAndNotify and waitUntilExit



I am trying to make use of "waitForDataInBackgroundAndNotify" when executing a script. I've setup the task like this

	NSTask *task = [[NSTask alloc] init];
	[task setLaunchPath:path];
	[task setArguments:args];

	NSPipe *outPipe = [NSPipe pipe];
	[task setStandardOutput:outPipe];
	NSFileHandle *outFile = [outPipe fileHandleForReading];

	NSPipe *errPipe = [NSPipe pipe];
	[task setStandardError:errPipe];
	NSFileHandle *errFile = [errPipe fileHandleForReading];	

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(errData:)
name:NSFileHandleDataAvailableNotification
object:errFile];


[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(outData:)
name:NSFileHandleDataAvailableNotification
object:outFile];


[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(terminated:)
name:NSTaskDidTerminateNotification
object:task];


    [outFile waitForDataInBackgroundAndNotify];
    [errFile waitForDataInBackgroundAndNotify];

    NSLog(@"launching command");
	[task launch];

    NSLog(@"waiting for command to finsh");
    [task waitUntilExit];

and while the I get and handle the "outData" call.

-(void) outData: (NSNotification *) notification
{
NSFileHandle *fileHandle = (NSFileHandle*) [notification object];


        NSLog(@"received out data");

        NSData *data = [fileHandle availableData];

if ([data length]) {
NSLog(@"appending out data");
[output appendString:[NSString stringWithCString:[data bytes] encoding: NSUTF8StringEncoding]];
}


        [fileHandle waitForDataInBackgroundAndNotify];

        NSLog(@"receiving out done");
    }

There is seems to be no NSTaskDidTerminateNotification and the task is just sits there and waits

    launching command
    waiting for command to finsh
    received out data
    appending out data
    receiving out done

While there is a lot to find about NSTask and waitUntilExit on the net I could not find anything when waitForDataInBackgroundAndNotify is used.
Pointers what I am doing wrong?


cheers
--
Torsten
_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.