CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Forcing output before script finishes

 



kencl
User

Apr 12, 2000, 12:43 PM

Post #1 of 2 (459 views)
Forcing output before script finishes Can't Post

I have a script which unlocks a file, prints a webpage, then locks the file. The webpage initiates the download with <body onLoad="location.href='https://domain.com/~username/path/filename.exe'">

The problem is that the page is not sent to the browser until the script completes, by which time the file has been relocked.


Code
chmod(0600, "filename.exe");  # user read/write 
&PrintWebpage; # prints complete webpage
sleep(50); # gives the download a chance to start
chmod(0200, "filename.exe"); #user write only

Code
 
Suggestions? Thanks.


Jasmine
Administrator / Moderator

Apr 12, 2000, 2:53 PM

Post #2 of 2 (459 views)
Re: Forcing output before script finishes [In reply to] Can't Post

To make a program display its results as it executes (opposed to when the script completes), you can flush the Perl buffer by using:

$|=1;

$| is the variable for the perl buffer. By default, it's set to not flush (false). So by making the value 1 (true), the buffer will flush as soon as there's something to output, and will continue to do so until the program completes.

Note that while the program will flush with $|=1, the javascript onLoad command waits until all elements of the page are loaded. Depending on your images and other page elements, and the what the program does after the unlocking, there may not be enough time before the onLoad command is invoked before the file is relocked.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives