Results 1 to 11 of 11
  1. #1
    Join Date
    Jan 2003
    Posts
    81

    Pausing the script

    Could somebody please tell me what command I need to use to pause my Perl script? What I am trying to do is pause my script for 30 seconds somewhere in the middle and then continue to run it from the same place that I paused it at. Is it possible to do?

  2. #2
    Join Date
    Dec 2001
    Location
    NYC, NY
    Posts
    798
    sleep(30);

  3. #3
    Join Date
    Jan 2003
    Posts
    81
    Thank you very much for the reply. However, when I am trying to use that command after I want to print something, for some reason the script first goes to sleep and then prints. Here is just an example:

    #!/usr/bin/perl
    print "Content-type: text/html\n\n";
    print "A";
    sleep (30);
    print "B";

    So basically, what I want to do is print "A" then wait 30 seconds and then print "B". However, what the script does is first it waits for 30 seconds, then prints "A" and then immediately prints "B".

  4. #4
    Join Date
    Dec 2001
    Location
    NYC, NY
    Posts
    798
    First in order for that to work on a console.. you'd need to add a \n to the print. Now in order for it to work via a website.. you need to flush the buffer.. try this


    #!/usr/bin/perl
    print "Content-type: text/html\n\n";
    print "A \n <br>";
    select(STDOUT);
    $|=1;

    sleep (30);
    print "B \n <br>";


    the \n are there for console.. and the <br> is there for the web

  5. #5
    Join Date
    Jan 2003
    Posts
    81
    Thanks again for the reply. Unfortunately, when I tried your code, I got the same problem. The system first hangs for 30 seconds and then immediately prints A and B. What I need is to first print A then pause for 30 seconds and then print B.

  6. #6
    Join Date
    Dec 2001
    Location
    NYC, NY
    Posts
    798
    my example works on my webserver.. check out

    http://homer.meso.com/cgi-bin/test.cgi

    edit: works fine in mozilla.. looks like its IE you're using.. if you load my page.. wait for it to load.. then refresh.. it works.. just not if you first load it.. hmm

  7. #7
    Join Date
    Jan 2003
    Posts
    81
    Hmmmm... it does work in Netwscape. How come it doesn't work in IE?

  8. #8
    Join Date
    Dec 2001
    Location
    NYC, NY
    Posts
    798
    it must be how IE parses the pages.. it might want for the tcp stream to finish before it displays the page.. I'll look into it more.. i might be able to find a way

  9. #9
    Join Date
    Jun 2003
    Location
    Sydney, Australia
    Posts
    158
    I tried it in IE6 and got "a" and "b" at the same time.
    Also tried it in Mozilla 1.6 and got "a" instantly and then "b" about 10 seconds later.

    Good old Microsoft..

  10. #10
    Join Date
    May 2004
    Posts
    10
    you need to use the user defined flags to control the behavior. So you can exactly control the script execution.

    Define two variables as boolean and change the value when A is done so you can check it's value when you want to start B until that flag is ON.

    It will be simpler with this approach.

  11. #11
    Isn't something similar to php's flush() function in Perl?
    Hosting: Evolve Romania
    Scripting: Azteck Korp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •