#!/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 = ) { 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: $!"; } #### #!/usr/bin/perl print <<'EOCGI'; Content-Type: text/html
Pipe Demo
  foo
  bar
  baz
EOCGI ##
## $ ./813729.pl CGI said: Content-Type: text/html CGI said: CGI said: CGI said:
Pipe Demo
CGI said: CGI said:
CGI said:   foo
CGI said:   bar
CGI said:   baz
CGI said: 
CGI said: CGI said: