In article <pan.2005.10.04.12.11.37.993986@'remove_me'sit.fra unhofer.de>, Mathias Herrmann <herrmann@'remove_me'sit.fraunhofer.de> writes:
>
> My question is now: is it possible to tell stdout not to buffer anything,
Yes:
#include <stdio.h>
int main(void)
{
int ret;
ret = setvbuf(stdout, NULL, _IONBF, 0);
if (ret == 0)
puts("stdout is now unbuffered");
return 0;
}
> but immediately print it out.
No. While you can disable the C library's buffering for stdout
(if setvbuf succeeds), you don't have any control over when the
underlying system processes the output generated by the C library.
However, I believe you've asked the wrong question, since you
appear to want to change the stdout buffering for another process,
without changing that program's source code. That you cannot do,
in standard C. (Note that popen is not part of the standard C
library.)
I suggest you take this question to a newsgroup that deals with
popen, such as comp.unix.programmer, or one specific to your
operating system. (OT: Unless I am gravely mistaken, there's no
POSIX/SUS mechanism to force another process to disable stdio
buffering, either. Using a pseudo-tty rather than a pipe should
get you line buffering rather than full buffering, though, which
might suffice.)
--
Michael Wojcik
You brung in them two expert birdwatchers ... sayin' it was to keep us from
makin' dern fools of ourselfs ... whereas it's the inherent right of all to
make dern fools of theirselfs ... it ain't a right held by you official types
alone. -- Walt Kelly