Re: trying to control the output of a subprocess.
Re: trying to control the output of a subprocess.
- Subject: Re: trying to control the output of a subprocess.
- From: Greg Guerin <email@hidden>
- Date: Thu, 4 Sep 2008 10:44:04 -0700
Nicholaz Beresford wrote:
Just guessing but if you can get a posix stream (FILE *)
you can try to use setbuf(stream, NULL); Under posix
functions I'd do that after the fork() before exec()
but I have no idea how this works in Cocoa.
If you call setbuf() between fork() and exec(), it only affects the
FILE* until the exec(), because a FILE* is the memory address of a
FILE struct, not a heritable file-descriptor. Once the exec()
occurs, the child process's memory is completely replaced by the new
executable's code and data, and a completely new set of FILE*'s
appears in the new executable. As a result, setbuf() is effectively
not heritable, AFAIK.
Even if setbuf() were heritable, there is nothing to prevent the new
executable from calling setbuf() again using its own buffer, thereby
reversing the pre-exec() call to setbuf(). Many programs will, in
fact, call setbuf() according to whether they detect the stdio
streams being attached to a tty or not. Or they will do it in
response to a particular command-line option.
Read 'man setbuf' and note what it says about line buffering and
streams attached to terminals. That's why I think that a pseudo-tty
is the main (or even only) way to do this, without having source to
the command being exec()'ed.
-- GG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden