(I've posted here on the idea that apache is doing something odd. I've posted this
similar question to the appropriate perl and cgi groups too)
I'm seeing strange results when using perl's CGI.pm and IPC::Open3 together.
Any clues? Am I, perl, CGI.pm, apache, or none or some of the above at fault here?
Here's a simple cgi to illustrate:
#!/usr/local/bin/perl -w
# example.cgi: A perl CGI to demonstrate a problem with open3
# Tested with apache 1.2.6 and 1.3.3 and perl 5.00404 and perl5.00502
# with CGI.pm version 2.43
use CGI;
use IO::Handle;
use IO::File;
use IPC::Open3;
use strict;
# With this line, it at leaset works under apache-1.2.6, but
# results in absolutely no output on apache-1.3.3
# autoflush STDOUT 1;
my $ex = new CGI;
print $ex->header(),
$ex->start_html(),
$ex->h1("Example cgi"),
"An example of a badly behaving cgi script", $ex->hr;
my $reader = new IO::Handle;
my $writer = new IO::Handle;
# This can be ANY external program, I use cat as an example
my $PID = open3($writer,$reader,'', "/bin/cat");
print $writer "Hello1... $PID...\nblah... blah...\n";
undef $writer; # flush/close output TO cat
print <$reader>; # read output FROM cat
print $ex->end_html;
Here are my findings:
This script works on the command line fine.
This script gives quasi double-printed output when executed under apache 1.2.6. See an
example of what I mean at http://www.math.unl.edu/~rdieter/Projects/example
This script executes fine when STDOUT is autoflushed under apache 1.2.6
This script executes, but prints no output from the open3'd process under apache 1.3.3.
This script produces no output (ie, browser says document has no data), when STDOUT is
autoflushed under apache 1.3.3.
A few more details
Platform: NEXTSTEP 3.3 and Openstep for Mach 4.2
Perl: versions 5.004_04 and 5.005_02
CGI.pm: version 2.43
Apache: versions 1.2.6 and 1.3.3
--
Computer System Manager http://www.math.unl.edu/~rdieter/
Mathematics and Statistics
University of Nebraska-Lincoln