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: Sat, 11 Apr 2009 17:11:02 -0400
On Sat, Apr 11, 2009 at 2:29 PM, Michael Domino
<email@hidden> wrote:
> Ken,
>
> I ended up throwing out NSTask in favor of popen for running hdiutil, and my
> code seems much more stable now. Did I shoot myself in the foot some other
> way? I'm executing this in a pthread of its own. I also kept getting
> exceptions thrown for nil arguments to NSConreteTask, besides the problems
> getting the standard output either partially or not at all. This seems
> better:
>
> FILE *instream = popen(cmdbuf, "r");
You should basically never use popen(). The reasons are the same for
why you should never use system(): it spawns a shell, and performs
shell processing on your argument, which adds about a zillion
different opportunities for things to go wrong if, for example, you
have unusual characters in your arguments.
Since apparently you don't need separate stderr and stdout, I'm
curious as to why you were using the big complicated two-pipe approach
with NSTask. Using a single output pipe with NSTask is vastly simpler
and doesn't require any runloop stuff, just a single call to
readDataToEndOfFile.
If you really can't use NSTask (if you gave up due to getting
exceptions about nil arguments, you should stop passing it nil
arguments) then you should spawn the subprocess using more manual
methods like fork/exec or posix_spawn. It's unfortunate that there are
no decent subprocess spawning APIs in libc, but there we are.
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