473,804 Members | 3,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to stop bufferring on STDOUT

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

Nov 14 '05 #1
4 8355
In article <bt************ @ID-166953.news.uni-berlin.de>,
Ramprasad A Padmanabhan <ra*******@netc ore.co.in> wrote:
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 flush the output buffer of printf(), see:
http://www.eskimo.com/~scs/C-faq/q12.4.html

Regards,
--
Rob van der Leek | rob(at)ricardis (dot)tudelft(do t)nl
Ricardishof 73-A | http://www.ricardis.tudelft.nl/~rob
2614 JE Delft, The Netherlands
+31 (0)6 155 244 60
Nov 14 '05 #2
On Mon, 12 Jan 2004 13:53:17 +0530, Ramprasad A Padmanabhan
<ra*******@netc ore.co.in> wrote:
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'

--
Mohan
Nov 14 '05 #3
"A. J. Mohan Rao" <aj*********@ft h7.siemens.de> wrote:
On Mon, 12 Jan 2004 13:53:17 +0530, Ramprasad A Padmanabhan
<ra*******@netc ore.co.in> wrote:
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.


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
Nov 14 '05 #4
"A. J. Mohan Rao" <aj*********@ft h7.siemens.de> wrote:
On Mon, 12 Jan 2004 13:53:17 +0530, Ramprasad A Padmanabhan
<ra*******@net core.co.in> wrote:
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'


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
--
Irrwahn Grausewitz (ir*******@free net.de)
welcome to clc : http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.eskimo.com/~scs/C-faq/top.html
acllc-c++ faq : http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html

Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
3833
by: shyren | last post by:
Hi All, I have a php program which calls a c++ program using exec. However when user presses stop button in the browser or closes it this program keeps on running on the server. How can I stop it according to user's actions. Thanks in advance. Sal
3
2761
by: dh | last post by:
Runtime.getRuntime().exec() ... mad buffering of stdout ... It buffers stdout without limit ... so if your Java program doesn't keep up with the Process output then memory fills up! I wish it just blocked instead because my Java program is loosing the race against the C program that it exec()s. The pattern I want is "producer-consumer" and i'm suprised that it seems imposible.
10
9656
by: hokiegal99 | last post by:
How can I make this script run w/o seeing a cmd popup window on the screen? The script works well, but each hour (when the task scheduler runs it) a brief cmd window appears and then goes away. It's only on the screen for a second or two, but it's noticable. u = "User Name" f = "from address" t = "to address" fp = os.popen("ipconfig /all", "r")
0
1454
by: BS | last post by:
Hi All, This may be an old question, but there's little useful references online that I've been able to find. I want the following code to display bit by bit, not send all at once to the client (IE). The following code sample works as intended on all NT4 Wkstation PWS and on *one* IIS6 W2K3 server. On all other W2K3 servers it does not, it waits and
4
3821
by: midday.hu | last post by:
Hi, Does someone know how to stop "the information output on screen"? Now when I run my code, it outputs a lot of message when calling other libraries, together with the info with the print command I used. How can I mask these info on screen when calling other libraries and how I can mask the info output produced by the print command? Is there a way to mask them separately.
3
1541
by: SS | last post by:
It seems that my code locks my machine up after the " fclose(datafile);" command I guess I'm not following the next bit of code on properly. Can someone help me out?? SS ============================================================================ ========== # include <stdio.h> main ()
30
4595
by: siliconwafer | last post by:
Hi All, I want to know tht how can one Stop reading a file in C (e.g a Hex file)with no 'EOF'?
9
18294
by: Santtu Nyrhinen | last post by:
Hi, Let say that I have a function like void writeHello() { printf("Hello"); } Now I need to make an automated test fot that function. The test function returns 1 for successful and 0 for unsuccessful test. int Test_writeHello() {
2
2328
by: CC | last post by:
Hi: I've conjured up the idea of building a hex line editor as a first real Python programming exercise. To begin figuring out how to display a line of data as two-digit hex bytes, I created a hunk of data then printed it: ln = '\x00\x01\xFF 456789abcdef' for i in range(0,15):
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10311
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2988
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.