Apache and Perl in Windows

A

Arn Anderson

Hi and Merry Christmas. I am having a problem. The cgi scripts execute,
but the output is empty. I am studying a spider book that uses Perl so I
download perl and Apache, then uncomment out the lines in the web.xml
file in apache and rename the jar files in the server directory. Then I
launch apache and run my script using an HTML file. The script executes,
but I don't see any results. Perl works fine separately and so does
Apache. But together, they don't. Here is the source code for the 2
files. I think this has to do with permissions, but when I installed
Apache, I used the same account and password as my Windows username and I
am administrator. I am out of ideas. If anyone knows what is going wrong,
I would appreciate the help. Thank you.

<HTML>
<HEAD>
<TITLE>Environment Variables
using GET</TITLE>
</HEAD>
<BODY>
<FORM ACTION="cgi-bin/exp.cgi" METHOD="GET">
Press submit for a list of environment variables. <BR>

First Name: <input type=
"text" name="fname" size=
30><p>
Last Name: <input type="text"
name="lname" size=30><p>
<input type="submit">
</form>

<FORM>
</BODY>
</HTML>




#!c:\Perl\bin\perl.exe
use CGI qw:)all);
use Strict;
use LPW::Simple;

print "Content-type: text/plain\n\n";

foreach $var (sort keys %ENV) {
print "$var=\"$ENV{$var}\"\n";
}

@values = split(/&/,$ENV{'QUERY_STRING'});
foreach $i (@values) {
($varname, $mydata) = split(/=/,$i);
print "$varname = $mydata\n";
}
 
B

Brian Wakem

Arn said:
Hi and Merry Christmas. I am having a problem. The cgi scripts execute,
but the output is empty. I am studying a spider book that uses Perl so I
download perl and Apache, then uncomment out the lines in the web.xml
file in apache and rename the jar files in the server directory. Then I
launch apache and run my script using an HTML file. The script executes,
but I don't see any results. Perl works fine separately and so does
Apache. But together, they don't. Here is the source code for the 2
files. I think this has to do with permissions, but when I installed
Apache, I used the same account and password as my Windows username and I
am administrator. I am out of ideas. If anyone knows what is going wrong,
I would appreciate the help. Thank you.

<HTML>
<HEAD>
<TITLE>Environment Variables
using GET</TITLE>
</HEAD>
<BODY>
<FORM ACTION="cgi-bin/exp.cgi" METHOD="GET">
Press submit for a list of environment variables. <BR>

First Name: <input type=
"text" name="fname" size=
30><p>
Last Name: <input type="text"
name="lname" size=30><p>
<input type="submit">
</form>

<FORM>
</BODY>
</HTML>




#!c:\Perl\bin\perl.exe
use CGI qw:)all);
use Strict;


Should be lower case s.

use LPW::Simple;


I don't believe this module exists, so your code does not compile.

print "Content-type: text/plain\n\n";


Why use the CGI module and print your own headers?

foreach $var (sort keys %ENV) {


Global symbol "$var" requires explicit package name at ....

print "$var=\"$ENV{$var}\"\n";
}

@values = split(/&/,$ENV{'QUERY_STRING'});


Global symbol "@var" requires explicit package name at ...

There are many more errors. I can't be bothered to point them all out.
Needless to say the code does not compile.
 
P

Paul Lalli

Brian said:
Should be lower case s.

Should be, but Windows Perl won't complain about it. It also won't
actually load the strict pragma. This is a completely meaningless and
useless statement.
Global symbol "$var" requires explicit package name at ....

The OP wouldn't have gotten that error, because strict.pm is not
actually loaded.
Global symbol "@var" requires explicit package name at ...

Pretty sure you meant "@values", but again, the OP wouldn't have
gotten this.
There are many more errors. I can't be bothered to point them all out.
Needless to say the code does not compile.

With the LWP/LPW typo, I have to agree with this. The strict
violations, however, do not prevent compilation.

Paul Lalli
 
A

Arn Anderson

Thanks all for the posts. Here's one example that came straight from the
Oreilly Spidering Hacks book that will not work in Windows with Apache. I
have no clue as to why because it will work fine from the command line in
ActiveState perl. And ActiveState has the LWP module already installed.
Does ActiveState work better in IIS? I prefer Apache, but I've spent 2
days just trying to figure this out. Is ActiveState the recommended
version of Perl for Windows that you experts recommend?

#!/usr/bin/perl -w (I replaced with #!c:\Perl\bin\perl.exe)
use strict; (I removed this)
use LWP::Simple; (I have use LWP::simple)


# Just an example: the URL for the most recent /Fresh Air/ show
my $url = 'http://freshair.npr.org/dayFA.cfm?todayDate=current';

my $content = get($url);
die "Couldn't get $url" unless defined $content;

# Do things with $content:
if ($content =~ m/jazz/i) {
print "They're talking about jazz today on Fresh Air!\n";
} else { print "Fresh Air is apparently jazzless today.\n"; }
 
C

ced

Arn said:
Thanks all for the posts. Here's one example that came straight from the
Oreilly Spidering Hacks book that will not work in Windows with Apache. I
have no clue as to why because it will work fine from the command line in
ActiveState perl. And ActiveState has the LWP module already installed.
Does ActiveState work better in IIS? I prefer Apache, but I've spent 2
days just trying to figure this out. Is ActiveState the recommended
version of Perl for Windows that you experts recommend?

#!/usr/bin/perl -w (I replaced with #!c:\Perl\bin\perl.exe)
use strict; (I removed this)
use LWP::Simple; (I have use LWP::simple)


# Just an example: the URL for the most recent /Fresh Air/ show
my $url = 'http://freshair.npr.org/dayFA.cfm?todayDate=current';

my $content = get($url);
die "Couldn't get $url" unless defined $content;

# Do things with $content:
if ($content =~ m/jazz/i) {
print "They're talking about jazz today on Fresh Air!\n";
} else { print "Fresh Air is apparently jazzless today.\n"; }

Have you checked the Apache error logs..., ensured the headers are
correct?
checked CGI FAQ's...? Try 'perldoc -q cgi' for a list of pointers,
URL's and
helpful tips if you haven't already.

If you still can't resolve the problem, the heavier duty LWP modules
may
need to be used to pinpoint the problem, eg. See 'Hack #10. More
involved
Requests with LWP::UserAgent ' in 'Spidering Hacks'.

hth,
 
A

Arn Anderson

I have not been able to resolve this problem, but as a note to future
programmers who might run into this problem, Perl from ActiveState simply
is not very compatible with Apache. Here is the code I ran in IIS and
Apache. Both used the same perl. Only difference is that Apache shows no
results while IIS printed out "Fresh Air is apparently jazzless today.
\n". If anyone has an answer to why IIS works and Apache does not, I
would be interested to know. But for now, I will have to use IIS.


#!c:\Perl\bin\perl.exe
use LWP 5.64;

print "Content-type: text/plain\n\n";

$url = 'http://freshair.npr.org/dayFA.cfm?todayDate=current';

$browser = LWP::UserAgent->new;
$response = $browser->get( $url );

die "Can't get $url -- ", $response->status_line
unless $response->is_success;

die "Hey, I was expecting HTML, not ", $response->content_type
unless $response->content_type eq 'text/html';

if ($response->content =~ m/jazz/i) {
print "They're talking about jazz today on Fresh Air!\n";
} else {
print "Fresh Air is apparently jazzless today.\n";
}
 
A

Arn Anderson

Have you checked the Apache error logs..., ensured the headers are
correct?
checked CGI FAQ's...? Try 'perldoc -q cgi' for a list of pointers,
URL's and
helpful tips if you haven't already.

If you still can't resolve the problem, the heavier duty LWP modules
may
need to be used to pinpoint the problem, eg. See 'Hack #10. More
involved
Requests with LWP::UserAgent ' in 'Spidering Hacks'.

hth,

Thanks. I did check the log file in Apache and nothing shows up. I
believe the problem could be with the fact that Apache is calling perl
using some sort of "execute program" method in Java and Windows 2000 does
not like this for some reason. But I guess IIS allows this because I
checked on the box in IIS to allow cgi scripts to execute programs in
Windows. Just a hunch.
 
A

A. Sinan Unur

Arn Anderson said:
#!/usr/bin/perl -w (I replaced with #!c:\Perl\bin\perl.exe)
Why?

use strict; (I removed this)
Why?

use LWP::Simple; (I have use LWP::simple)

Why?


Sinan
 
S

Scott Bryce

Arn said:
Perl from ActiveState simply is not very compatible with Apache.

Your script works fine for me run as a CGI script on my machine.

Apache 2.0.48
ActiveState Perl 5.8.2
Windows 98SE
 
T

Todd W

Arn Anderson said:
I have not been able to resolve this problem, but as a note to future
programmers who might run into this problem, Perl from ActiveState simply
is not very compatible with Apache.

<snip>

This is not true. On a properly configured system Apache and ActiveState
perl work absolutely fine together.

Todd W.
 
H

Henry Law

A. Sinan Unur said:

Apache under Windows checks the shebang line and if it's not valid emits
a not-terribly-informative "The system cannot find the path specified.
: couldn't spawn child process: ..." message. I spent a very
frustrating afternoon a week or two back debugging this one.
 
A

A. Sinan Unur

Henry Law said:
Apache under Windows checks the shebang line and if it's not valid emits
a not-terribly-informative "The system cannot find the path specified.
: couldn't spawn child process: ..." message. I spent a very
frustrating afternoon a week or two back debugging this one.

Hmmm ... See:

<URL:http://httpd.apache.org/docs/2.0/mod/core.html#scriptinterpretersource>

<URL:http://groups.google.com/group/comp.lang.perl.misc/msg/2c41b461d98a586b>

<URL:http://groups.google.com/group/comp.lang.perl.misc/msg/2ba2cd005a3cf1f7>

Sinan
 
A

A. Sinan Unur

Whereas A. Sinan Unur could with trivially extra effort have written


Your "Hmmm" drips disapproval.

Of course, it does, since you could have, yourself, trivially, with
little extra effort, searched the archives of this newsgroup, or read
the Apache documentation, to find out why one need not change shebang
lines to run Perl scripts under Apache for Windows.

Or, you could have, easily, trivially, with little extra effort, say
"oh, I did not know that, my assertion was unfounded", thanked for the
pointers, and moved on.

Oh well.

Sinan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top