Perl Problems
March 15, 2004 9:04 PM   Subscribe

Hoping this isn't too obscure, but here goes:

So I've got a perl CGI script. That script kicks off another process using system (or exec, or backticks, same difference.) That other process takes a long time, and produces a lot of output, which I'd like to stream to the browser continuously -- or at least often enough to keep the connection open -- instead of waiting for it to end before flushing the buffer.

I know how to use $| to get perl to autoflush its own output. How do I do the same for the system process being called from within perl?
posted by ook to Education (5 answers total)
 
Setting "$| = 1" before your exec should work. What happens?
posted by waxpancake at 9:58 PM on March 15, 2004


I don't really do perl, but based on experience with other languages I imagine you want to open a pipe to the process. Apparently one uses open to get a handle for the pipe, which you can then read as frequently as you would like to update the browser.

Perl gurus may feel free to shoot me down.
posted by Galvatron at 9:58 PM on March 15, 2004


Try perldoc perlopentut, look for the word "pipe."
posted by majick at 10:06 PM on March 15, 2004


That did the trick, majick. (Still comes out in ~10K chunks, instead of flushing after every newline -- but that's at least frequent enough to keep the browser connection open.)

Thanks!
posted by ook at 10:45 PM on March 15, 2004


You're welcome.

It sounds like you ought to play some more with $|. Have a peek at this example of how to apply autoflush to different filehandles. Just putting $| = 1; at the top of your script isn't going to do all the things you think it should do.
posted by majick at 12:44 AM on March 16, 2004


« Older Was My Expired Domain (hosted by eNom) Already...   |   What's going on with this site? Newer »
This thread is closed to new comments.