Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difference between STDOUT on Windows and Linux

Status
Not open for further replies.

Tyger

Programmer
Sep 19, 2001
21
GB
I have written a script which opens a file handle and then prints the file to the browser with appropriate headers so that the user must download the file, rather than seeing it displayed:

print "content-disposition: attachment; filename=\"thefile.bin\"\n";
print "content-type: application/octet-stream\n\n";
binmode(STDOUT);
open (DOWN, &quot;< thefile.bin&quot;);
binmode(DOWN);
print <DOWN>;
close DOWN;

I was originally writing this on Windows 2k and it works fine with small-ish files but when I tested it with a 100MB file there was a lot of prolonged hard disk activity and it did not work.

However, I have tried it on a Linux machine and it seems ok. Is this the difference between STDOUT on Windows and Linux? The hard disk activity would suggest that Windows is caching the entire contents of STDOUT before sending it to the browser wheras Linux streams it. Is this the case? Is it buffering the output? Setting $|=1 on my Windows system doesn't appear to have any effect.

I don't really know enough about how the OS's deal with files in this respect or whether the webserver is playing a part in determining the behaviour of STDOUT. I have experienced a similar effect in a script handling user uploads of large files.

Many thanks.
Tyger.
 
Windows cannot stream STDOUT. The $| is disabled on all Win32 implimentations of Perl.

The reason is that Win32 machines are not able to handle threading and multiprocessing, whereas Linux (and many other flavours of Unix) can. As a result on Win32 machines, files are cached and then sent as a complete chunk. Barbie
Leader of Birmingham Perl Mongers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top