On Fri, Apr 3, 2009 at 9:36 AM, Michael Domino <michael.dom...@identityfinder.com> wrote: > Hi all, > > I have a task prepared and launched with the code below, and when it returns > (in this situation that status code returned from terminationStatus is 0), > it hangs in availableData, never to return. The stack at this point is very > deep because of a recursive function (see the stack trace below), which > might be a factor in this hanging problem. Could this be a problem with the > stack depth? This code functions perfectly most of the time. > > messagePipeError = [NSPipe pipe]; > messagePipeOutput = [NSPipe pipe]; > [task setLaunchPath:@"/usr/bin/hdiutil"]; > [task setArguments:[NSArray > arrayWithObjects:@"info", nil]]; > [task setStandardError:messagePipeError]; > > [task setStandardOutput:messagePipeOutput]; > > [task launch]; > [task waitUntilExit]; > status = [task terminationStatus]; > > NSData *messageDataError = [[messagePipeError > fileHandleForReading] availableData]; > messageError = [[[NSString alloc] > initWithData:messageDataError encoding:NSUTF8StringEncoding] autorelease];
I don't know if this is the cause of your problem or not, but never, ever do this. Don't call waitUntilExit before you read. Pipes have a small buffer (4kB?) and if it fills up then further writes will block. This means that if you do a waitUntilExit while the subprocess is writing more data than the pipe can buffer, you'll deadlock. The subprocess will be waiting for you to read data before it can continue, and you will be waiting for it to exit before you read data. Read all data (using readDataToEndOfFile or equivalent) *before* you do waitUntilExit. Mike _______________________________________________ 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 arch...@mail-archive.com