buffer the output


 
Thread Tools Search this Thread
Top Forums Programming buffer the output
# 1  
Old 11-06-2004
MySQL buffer the output

Hai Friends

I am writing a cgi program in C. The CGI program has a link to start my tcp chat server... The tcp chat server prints some information when it starts... I have captured the informations and sent to the client browser through the cgi program... But the output is displayed all atonce...But my need is that i have to print the string immediately like how it gets printed on the terminal when i start the server.....

Can anyone help me with this issue...and provide me a detailed explanation

Thanks in advance
# 2  
Old 11-06-2004
Use setvbuf to unbuffer the output. man page
# 3  
Old 11-07-2004
i tried this way

I tried this.. But still its of no use.... Any other way..?


main()
{
int i;
setvbuf(stdout,NULL,_IONBF,0);
printf("Content-Type: text/html\n\n");
printf("Hello");
printf("Hai");
printf("Bye");
sleep(5);
printf("Hello");
printf("Hai");
printf("Bye");
}


My output in browser should be like
Hello Hai Bye
(and after few seconds)
Hello Hai Bye


Collins
# 4  
Old 11-07-2004
I could not even get that to compile. I had to add a line
#include <stdio.h>

At that point, I got the timing effect that you wanted but the output is:

$ ./xx
Content-Type: text/html

HelloHaiByeHelloHaiBye$

You need to add some spaces and newlines to the printf's.

Run your program in the unix environment from the terminal. Do you still see line buffering? If so, your stdio package has a bug. If it works from the terminal but not in the browser, then the buffering must happening elsewhere.
# 5  
Old 11-09-2004
Still....?

Hai

I have mensioned in my question itself that i am using CGI program and i need to get the output in the browser.... I have added all the stdio.h and the <br> tag to get the output in the new line... But my exact requirement is that i have to get the output as

Hello Hai Bye
(after some time)
Hello Hai Bye

In the Browser when i call the cgi program which is written in C.
# 6  
Old 11-09-2004
Please try this ....

add <html> </html>
to print the text on the browser ...

Following may work .... ; I have n't tried as there is no env :-)



main()
{
int i;
setvbuf(stdout,NULL,_IONBF,0);
printf("Content-Type: text/html\n\n");
printf("<html>") ;
printf("Hello");
printf("Hai");
printf("Bye");
sleep(5);
printf("Hello");
printf("Hai");
printf("Bye");
printf("</html>") ;
}
# 7  
Old 11-09-2004
sorry...still...?

hai bhargav


No bhargav

Still its not working.... Can you suggest me any other idea....

Thanks
Collins
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Jumbled output in expect_out(buffer)

I have a code like this : set ipv6_acl_max_chars test_acl_max_chars123456a789%s%d2345678ww134rt789qa23456789012345%c89012%a56789012x4r67890test_acl_max_chars1234567890.01234aabcdob34567aBC0 spawn telnet $myip expect "Login:" { send "admin\r" } expect "Password:" {send "admin\r" }... (0 Replies)
Discussion started by: ylucki
0 Replies

2. Programming

buffer in C

Hello, size_t write(int fd, const void *buf, size_t count) { static size_t (*write_func)(int, const void *, size_t) = NULL; if (!write_func) write_func = (size_t(*)(int, const void *, size_t)) dlsym(RTLD_NEXT, "write"); char tmp; memcpy(tmp,buf,count); ... (3 Replies)
Discussion started by: chercheur857
3 Replies

3. UNIX for Dummies Questions & Answers

Vim external command output to new buffer

Hi, From inside Vim, I'm looking for a way to use the contents of the current buffer, pass it to an external executable, and then return the output from the executable into a new Vim buffer. I know that I can do something like %!<executable>, but that will overwrite the contents of the... (3 Replies)
Discussion started by: konfushus
3 Replies

4. UNIX for Dummies Questions & Answers

vi next buffer

Hello, I am using vi to edit file vi filea :e fileb and :e# to switch between filea and fileb Now, I'd like to have many files open at the same time and have a way to cycle between them. :bn does not work; when I type it, nothing happens... Is there something to add to the... (1 Reply)
Discussion started by: JCR
1 Replies

5. Shell Programming and Scripting

How to redirect the output to a buffer/clipboard ?

Hi, I was wondering if there is a way by which I can redirect the output of a command to the buffer so that if I do a Ctrl+v or Alt+v it should paste the data. Ex : cat myfile.txt | grep hello . Hello there 1 Hello there 2 The output of the file should go to the buffer(clipboard info) so... (1 Reply)
Discussion started by: preethgideon
1 Replies

6. Linux

Buffer IO error

Hi guys, Currently i have a IBM x366 running on Red Hat 4 attached to a DS4800. I've configured 10 LUNs to the server. Somehow, there is a lot buffer io error on device whenever it boot and when i issue the command dmesg. My kernel is 2.6.9-22.ELsmp. I've updated the hba qla2300 firmware to... (2 Replies)
Discussion started by: raybakh
2 Replies

7. HP-UX

Buffer Cache

What is the "Buffer Cache" used for? (1 Reply)
Discussion started by: ALTRUNVRSOFLN
1 Replies

8. UNIX for Dummies Questions & Answers

buffer question

Hi... I have a question about how many lines the window can remember... is there an environemtn varible for this I can change??? I'm not talking about how many previous commands it remembers. I am talking about how many lines it remembers and for how many lines I can press "page-up" and I can... (4 Replies)
Discussion started by: lmanchur.
4 Replies

9. UNIX for Advanced & Expert Users

vm and buffer cache

i have a serious doubht about the assignment of memory in hp-ux system . i read from somewhere that the page allocation in hp-ux is not unified unlike compaq . i wanted to know in hp-ux kernel ,once the pages are assigned for the univarsal buffer cache... (2 Replies)
Discussion started by: vish_shan
2 Replies

10. UNIX for Advanced & Expert Users

About Buffer

Hi, if someone now how can look the last commands has used for last week? (1 Reply)
Discussion started by: Niko
1 Replies
Login or Register to Ask a Question