Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I try to run something that will run very long time in a cgi script with a pipe. However, before it exit, I found the script get timeout.......how can I print out the stdout from the pipe while I am waiting, but keep the collected output as the same time? The program is executed from a safe pipe in perl 5.8.0 multi argument open() with "-|" operator.
  • Comment on Print the output from the pipe while waiting

Replies are listed 'Best First'.
Re: Print the output from the pipe while waiting
by kyle (Abbot) on Mar 07, 2008 at 13:50 UTC
Re: Print the output from the pipe while waiting
by scorpio17 (Canon) on Mar 07, 2008 at 14:16 UTC
    You might want to consider using AJAX - it's good for this type of thing. I wrote a demo to illustrate something similar a while back that might be useful to you.
Re: Print the output from the pipe while waiting
by halfcountplus (Hermit) on Mar 07, 2008 at 14:45 UTC
    this could be because of buffering. (perl actually does not send one line at a time; it waits for more FIRST unless you tell it differently).

    There is a very excellent and easy to understand explanation at: http://perl.plover.com/FAQs/Buffering.html

    Probably what you want is:
    
    use IO::Handle;
    STDOUT->autoflush;
    
    
    But do read the FAQ and all will become clear.
Re: Print the output from the pipe while waiting
by Anonymous Monk on Mar 07, 2008 at 14:38 UTC
    Thank you guys, the articles above are really helpful. This is the question that is little bit off-topic, but related to the pipe: I try to get the time of execution from the pipe, with time() and Time::HiRes, but I found it never accurate...Is this problem common? If so, how can I get the time correctly, especially I work with pipe?
Re: Print the output from the pipe while waiting
by halfcountplus (Hermit) on Mar 07, 2008 at 14:47 UTC
    this could be because of buffering. (perl actually does not send one line at a time; it waits for more FIRST unless you tell it differently).

    There is a very excellent and easy to understand explanation at: http://perl.plover.com/FAQs/Buffering.html

    Probably what you want is:
    use IO::Handle; STDOUT->autoflush;
    But do read the FAQ and all will become clear.
      Thank you your reply. The article is very detail. I know Buffering will give me the feeling of the dalaying, but the magical thing is: I called time() or Time::HiRes method before pipe call to capture the timestamp before the pipe opened, then I capture another timestamp after the pipe closed; while the program itself will display a time of execution as well. I found the time shown in perl is always less than the time shown in the pipe result largely......I checked the documentation and I am quite sure the time unit is correct and the method I used to get the interval is from the sample code, so I don't think this is the buffering problem...any idea?