Hi Ken,

This may be obvious, but when running from the command line, stdout and
stderr are often interleaved together, but on the web server you see stdout
in the browser and stderr in the web server error log.  Your script is
probably exiting with an error either at the 'get' line (line 6) or at the
'die' line (line 7), which is what 'die' does -- terminate your script.
Have you checked your web server error log to see what the error is on your
'get' call?


On Mon, Nov 23, 2009 at 7:17 AM, Ken Irwin <kir...@wittenberg.edu> wrote:

> Hi all,
> I'm moving to a new web server and struggling to get it configured
> properly. The problem of the moment: having a Perl CGI script call another
> web page in the background and make decisions based on its content. On the
> old server I used an antique Perl script called "hcat" (from the Pelican
> book<http://oreilly.com/openbook/webclient/ch04.html>); I've also tried
> curl and LWP::Simple.
> In all three cases, I get the same behavior: it works just fine on the
> command line, but when called by the web server through a CGI script, the
> LWP (or other socket connection) gets no results. It sounds like a
> permissions thing, but I don't know what kind of permissions setting to
> tinker with. In the test script below, my command line outputs:
> Content-type: text/plain
> Getting URL: http://www.npr.org
> 885 lines
> Whereas the web output just says "Getting URL: http://www.npr.org"; - and
> doesn't even get to the "Couldn't get" error message.
> Any clue how I can make use of a web page's contents from w/in a CGI
> script? (The actual application has to do with exporting data from our
> catalog, but I need to work out the basic mechanism first.)
> Here's the script I'm using.
> #!/bin/perl
> use LWP::Simple;
> print "Content-type: text/plain\n\n";
> my $url = "http://www.npr.org";;
> print "Getting URL: $url\n";
> my $content = get $url;
> die "Couldn't get $url" unless defined $content;
> @lines = split (/\n/, $content);
> foreach (@lines) { $i++; }
> print "\n\n$i lines\n\n";
> Any ideas?
> Thanks
> Ken

Reply via email to