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

Posted on 2005-05-10
Last Modified: 2012-06-22
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.
Question by:PWSwebmaster
    LVL 19

    Expert Comment

    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...");

    Author Comment

    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:

    Here's the code for that one:


    use CGI;

    $query = CGI::new();

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

    print "done";

    It just prints it all to the screen after 10 seconds.
    LVL 48

    Assisted Solution

    At the top of your script, add:


    This turns off buffering.
    LVL 19

    Accepted Solution

    or in a more readable form

    use English;

    Author Comment

    That's what I was looking for. Thanks.

    Both methods work so I'll split the points.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
    In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now