how to stop bufferring on STDOUT

  • Thread starter Ramprasad A Padmanabhan
  • Start date
R

Ramprasad A Padmanabhan

I am running a program within another and reading the output. My problem
is that all outputs are delayed because of bufferring


Can I tell printf to print all outputs immediately and not buffer it

Thanks
Ram
 
A

A. J. Mohan Rao

I am running a program within another and reading the output. My problem
is that all outputs are delayed because of bufferring


Can I tell printf to print all outputs immediately and not buffer it

you can make 'stdout' unbuffered by using 'setvbuf()' with _IONBF flag.
For more into see 'man setvbuf'
 
R

Richard Bos

A. J. Mohan Rao said:
you can make 'stdout' unbuffered by using 'setvbuf()' with _IONBF flag.

s/make/try to make/. There's no guarantee that it works. Even when
setvbuf() returns 0 (success), that only means that the C implementation
doesn't buffer stdout any more; the OS still might, and there might be
nothing you can do about it. But yes, setvbuf() is the function to try -
or setbuf(stdout, 0), which amounts to the same thing.
For more into see 'man setvbuf'

Or, indeed, your C book, which is more likely to be ISO-compatible.

Richard
 
I

Irrwahn Grausewitz

A. J. Mohan Rao said:
you can make 'stdout' unbuffered by using 'setvbuf()' with _IONBF flag.
For more into see 'man setvbuf'

Well, we're deep in implementation defined land here
[C99 7.19.3#3], so the suggested setvbuf call might
fail on some implementations.

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,135
Messages
2,570,783
Members
47,341
Latest member
hanifree

Latest Threads

Top