Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

Print a message to the browser while waiting for the script to do it's job.

This is probably very simple, but I can't seem to find anything on it.

How can I have a perl script print a message to the browser while it is still running? The script can take a couple minutes to finish and I want to let the user know it's working.
0
PWSwebmaster
Asked:
PWSwebmaster
  • 2
  • 2
2 Solutions
 
Kim RyanIT ConsultantCommented:
You could print a few intermediate messages as certain stages of your script completes. For eample if you are using CGI

use CGI;

$query = CGI::new();

print $query->header();
# set up code here
print $query->p("Setup complete....");
#... more code...
print $query->p("Stage 1 complete...");
0
 
PWSwebmasterAuthor Commented:
Doesn't seem to be what I need. It prints everything all at once after the script is done.

Here's a simple test script I did to try it:

http://216.180.246.40/cgi-bin/test.cgi

Here's the code for that one:

#!/usr/bin/perl

use CGI;

$query = CGI::new();

print $query->header();
# set up code here
print $query->p("pausing....");
sleep(5);
print $query->p("pausing complete....");
sleep(5);
print $query->p("complete...");

print "done";



It just prints it all to the screen after 10 seconds.
0
 
TintinCommented:
At the top of your script, add:

$|=1;

This turns off buffering.
0
 
Kim RyanIT ConsultantCommented:
or in a more readable form

use English;
$OUTPUT_AUTOFLUSH = 1;
0
 
PWSwebmasterAuthor Commented:
That's what I was looking for. Thanks.

Both methods work so I'll split the points.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now