"CGI script's standard handles (out/err/in) are connected to pipes set up by the webserver" what does this mean ?

A pipe is an OS-supplied means used for one-way interprocess communication.  That is, a pipe has two ends, one for reading and one for writing. Both ends are like normal file handles (except that they aren't seek-able).

Here's a quick sample in Perl to illustrate what a webserver typically does to run a CGI script (this is heavily simplified, and webservers like Apache of course do implement this in C, but you get the idea...):

#!/usr/bin/perl pipe RH, WH; # Perl's interface to the system call of the same name my $pid = fork(); die "fork failed" unless defined $pid; if ($pid) { # parent - the webserver process that handles the request close WH; # read the CGI's output from the pipe while (my $line = <RH>) { print STDERR "CGI said: $line"; # (this would be passed on to the browser...) } } else { # child - a new process which runs the CGI script close RH; close STDOUT; # connect stdout (more precisely: file descriptor 1) to # the writing end of the pipe open STDOUT, ">&WH" or die "open to pipe failed: $!"; exec "perl mycgi.pl" or die "exec of CGI failed: $!"; }

With the following sample mycgi.pl

#!/usr/bin/perl print <<'EOCGI'; Content-Type: text/html <html> <header><title>Pipe Demo</title></header> <body> <pre> foo bar baz </pre> </body> </html> EOCGI

the output produced by th above snippet would be

$ ./813729.pl CGI said: Content-Type: text/html CGI said: CGI said: <html> CGI said: <header><title>Pipe Demo</title></header> CGI said: <body> CGI said: <pre> CGI said: foo CGI said: bar CGI said: baz CGI said: </pre> CGI said: </body> CGI said: </html>

In reply to Re^3: display of output from cgi script by almut
in thread display of output from cgi script by manishrathi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.