On May 12, 2008, at 23:04, Shawn Erickson wrote:
Your placement of waitUntilExit is blocking the runloop which needs to
be running to service the background notifications you requested.
Ah ...I see. That makes sense.
If
you want async behavior then you cannot wait on the task (at least not
in the way you are currently attempting).
Review the following code example...
http://developer.apple.com/samplecode/Moriarity/listing5.html
Thanks for the pointer.
Well, actually I was just using waitForDataInBackgroundAndNotify
trying to understand the options.
Looking at http://www.cocoadev.com/index.pl?NSTaskWaitUntilExit I
would have thought this should work
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];
[task launch];
NSData *data;
while((data = [outFile availableData]) && [data length]) {
[output appendString:[NSString stringWithCString:[data bytes]
encoding: NSUTF8StringEncoding]];
}
while((data = [errFile availableData]) && [data length]) {
[error appendString:[NSString stringWithCString:[data bytes]
encoding: NSUTF8StringEncoding]];
}
[task waitUntilExit];
While it works just fine for executing "ps" even the most simple shell
script:
#!/bin/sh
echo "out"
echo "err" >&2
exit 0
gets stuck. No matter whether I call it directly or via "/bin/sh -c
pathtoscript". The first call to "availableData" just blocks. Looking
at the documentation ("if no data is available, the method blocks") I
am a little surprised as there should be some data available.
Any further suggestions or comments?
cheers
--
Torsten
_______________________________________________
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]