Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Output from CGI

by qadwjoh (Scribe)
on Mar 02, 2004 at 11:37 UTC ( #333223=perlquestion: print w/replies, xml ) Need Help??

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

Hi

I have a Perl CGI script which launches a second Perl script and prints the output from it. The only problem is, it only prints the output all in one go, when the program has run.

Is there anyway to rearrange this code so the CGI script prints the output as it gets it?
unless ($pid = open3(\*WRITE, \*READ, \*READ, $prog, $prog_args)) +{ print "<p>Error..."; return; } READ->autoflush(1); # waitpid $pid, 0; # ? unless ($pid) { print "<p>Error..."; close WRITE; close READ; return; } close WRITE; print "<br>"; while (<READ>) { if (/^Job/) { print "<b>$_</b><br>\n"; } elsif (/\w+/) { $_ =~ s/"(.*?)"/<b>$1<\/b>/g; print "$_<br>\n"; } } close READ;
Andrew

Replies are listed 'Best First'.
Re: Output from CGI
by davis (Vicar) on Mar 02, 2004 at 11:40 UTC

    It sounds like you're Suffering from Buffering


    davis
    It's not easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.
      Agreed, I had a similar problem with a CGI script in the past and put the following at the beginning of my script to solve it:
      $|++;
      Hope this works for you. :)
Re: Output from CGI
by markmoon (Deacon) on Mar 02, 2004 at 13:20 UTC
    Assuming that you're using CGI.pm (You are aren't you?) -nph mode (No parsed headers) might allow you to do this.

    markmoon
    --
    @a = ("a".."z"," ","-","\n");foreach $b ( 12,0,17,10,24,12,14,14,13,26,8,18,26,0,26, 22,0,13,13,0,27,1,4,26,15,4,17,11,26,7,0, 2,10,4,17) {print $a[$b]};print $a[28];
    updatefixed link

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://333223]
Approved by b10m
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2021-09-25 05:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?