Re: Does waitUntilExit really mean that?
Re: Does waitUntilExit really mean that?
- Subject: Re: Does waitUntilExit really mean that?
- From: Michael Ash <email@hidden>
- Date: Mon, 6 Apr 2009 22:50:56 -0400
On Mon, Apr 6, 2009 at 1:47 PM, Michael Domino
<email@hidden> wrote:
> Hi all,
>
> Thanks for all the advice about how to make my pipe reads non-blocking, that
> works almost perfectly. I have a class now that handles the notifications
> (called msgTarget in the code snippet below). The puzzle here is the meaning
> of "waitUntilExit". My hdiutil info task was returning no data in both the
> output and error file handles. When I put in sleep(1), I started to get
> error strings, but no output strings. When I increased the wait to sleep(3),
> my standard output started coming through. Why would this be the case if
> waitUntilExit is actually waiting until the hdiutil task completes and
> exits? Is there some other latency in this process that my sleep() accounts
> for? I'd rather not rely on a kludge like this to get my output string. Is
> the problem using readToEndOfFileInBackgroundAndNotify instead of
> readInBackgroundAndNotify? I tried the latter call, but seem to get better
> results using readToEndOfFileInBackgroundAndNotify (or is that totally the
> wrong thing to do?).
>
>
> [task
> setLaunchPath:@"/usr/bin/hdiutil"];
> [task setArguments:[NSArray
> arrayWithObjects:@"info", nil]];
> [task
> setStandardError:messagePipeError];
> [task
> setStandardOutput:messagePipeOutput];
> NSFileHandle* readHandleError =
> [messagePipeError fileHandleForReading];
> [msgTarget
> setReadHandleError:readHandleError];
> NSFileHandle* readHandleOutput =
> [messagePipeOutput fileHandleForReading];
> [msgTarget
> setReadHandleOutput:readHandleOutput];
> [readHandleError
> readToEndOfFileInBackgroundAndNotify];
> [readHandleOutput
> readToEndOfFileInBackgroundAndNotify];
> [task launch];
> sleep(3);
> [task waitUntilExit];
> status = [task terminationStatus];
First off, I wouldn't write code like this. You have no guarantee that
readToEndOfFileInBackgroundAndNotify will actually read everything
while your code is stuck in waitUntilExit, so you have the same
potential for deadlock as before. It's quite possible that it
immediately starts reading on a background thread and so you're
perfectly safe, but it's bad to rely on that sort of thing. I'd just
ditch your waitUntilExit altogether. All you should really care about
is an end to the data coming in.
But as for your actual problem, my guess is that it has to do with the
fact that you're reading before you launch the task. I can't entirely
articulate why this would cause a problem, but it smells funny to me.
Try launching first, then reading, and see if it helps. But also just
dump the whole waitUntilExit business, you just don't need it and it's
no good for you here.
Mike
_______________________________________________
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