So, I don't know much about CGI. Your questions look pretty general to me, though. It seems you're asking about what incantations to use to put stuff in environment and redirect standard streams. Here is an example. I assume it's close enough to how CGI works. Note that there is no error handling whatsoever (I leave it as an exercise for the reader). Also note that it assumes Unix-like operating system.
# server.pl use strict; use warnings; use POSIX (); my $cgis = 0; $SIG{CHLD} = sub { while ( waitpid( -1, POSIX::WNOHANG ) > 0 ) { $cgis -= 1; } }; while (1) { print '(Ctrl-D to quit)> '; my $request = <STDIN>; last if not defined $request; chomp $request; print "Server: about to fork a CGI client\n"; $ENV{foo} = 'bar'; # use some real $ENV{baz} = 'quux'; # CGI variables pipe my ( $child_stdin, $input_to_child, ); pipe my ( $output_from_child, $child_stdout, ); my $pid = fork; if ( $pid == 0 ) { close $input_to_child; close $output_from_child; open STDIN, '<&', $child_stdin; open STDOUT, '>&', $child_stdout; exec {'perl'} 'perl', 'client.pl'; } else { close $child_stdin; close $child_stdout; print "Server: forked process $pid\n"; $cgis += 1; print $input_to_child $request; close $input_to_child; print "Server: reading child response\n", <$output_from_child>; } } print "Server exiting, remaining children: $cgis\n";
and client
# client.pl use strict; use warnings; my $input = <STDIN>; print <<END This is a pseudo-CGI client reporting. Process number $$ Got input "$input" \$ENV{foo} is "$ENV{foo}" \$ENV{baz} is "$ENV{baz}" End of report END

In reply to Re: How a web server sending data to a CGI perl script ? by Anonymous Monk
in thread How a web server sending data to a CGI perl script ? by exilepanda

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.