| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		habazlam -
 
  Joined: 19 Feb 2005 Posts: 2
 
  | 
		
			
				 Posted: Sat Feb 19, 2005 10:41 am    Post subject: Unwanted STDOUT buffering in Windows | 
				      | 
			 
			
				
  | 
			 
			
				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 | 
		
			          | 
		
	
	
		  | 
	
	
		aprelium -
 
  Joined: 22 Mar 2002 Posts: 6800
 
  | 
		
			
				 Posted: Sat Feb 19, 2005 9:27 pm    Post subject: Re: Unwanted STDOUT buffering in Windows | 
				      | 
			 
			
				
  | 
			 
			
				habazlam,
 
 
Perl buffers output by default.
 
 
To disable buffering, add the following line:
 
 
 
 
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 | 
		
			           | 
		
	
	
		  | 
	
	
		 |