Unwanted STDOUT buffering in Windows

 
Post new topic   Reply to topic    Aprelium Forum Index -> Perl
View previous topic :: View next topic  
Author Message
habazlam
-


Joined: 19 Feb 2005
Posts: 2

PostPosted: Sat Feb 19, 2005 10:41 am    Post subject: Unwanted STDOUT buffering in Windows Reply with quote

Hello,

I am unsuccessfully trying to accomplish "realtime" perl output to the browser:
Code:

#!/usr/bin/perl
$Header = qq|<html><head><title>Test</title></head><body>|;
$Footer=qq|</body></html>|;
$| = 1;
print "Content-type: text/html\n\n";
print $Header;

for ($x = 0; $x < 10; $x++)
{
print "Line $x<BR>\n";
sleep 1;
}
print $Footer;
exit;


Should be showing one line a second, not all 10 lines dumped at once after 10 second (like its doing) :(

Thanks for any help!
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Sat Feb 19, 2005 9:27 pm    Post subject: Re: Unwanted STDOUT buffering in Windows Reply with quote

habazlam,

Perl buffers output by default.

To disable buffering, add the following line:

Code:

 $| = 1;


So your code should like like:

Code:

#!/usr/bin/perl
$Header = qq|<html><head><title>Test</title></head><body>|;
$Footer=qq|</body></html>|;
$| = 1;
print "Content-type: text/html\n\n";
print $Header;

# No more buffering from now on.
$| = 1;

for ($x = 0; $x < 10; $x++)
{
print "Line $x<BR>\n";
sleep 1;
}
print $Footer;
exit;

_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Perl All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group