• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: trying to control the output of a subprocess.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: trying to control the output of a subprocess.
      • From: Nicholaz Beresford <email@hidden>
  • Prev by Date: Perplexed about "call of overloaded 'xxx' is ambiguous"
  • Next by Date: Tree View windows does not populate at all in MacOS X 10.4.x
  • Previous by thread: Re: trying to control the output of a subprocess.
  • Next by thread: Re: trying to control the output of a subprocess.
  • Index(es):
    • Date
    • Thread