cfreak has asked for the wisdom of the Perl Monks concerning the following question:

Okay here's what I'm trying to do I have a set of CGI scripts that run a particular website, the boss wants to see stats on this website. My company uses an SSI based stat generating program that is absolutly ancient because rant: the brain-dead administrators think that a log-file based stats generator running at 3am is processor intensive. /rant

Apache::SSI is out because we aren't running mod_perl (see admins, brain-dead above) and I haven't tried the CGI::SSI module but I am shying away somewhat since it states that it doesn't handle all SSI and frankly since I'm using HTML::Template already, it seems using SSI intermixed would just be ugly and annoyingly like using two template systems.

What I want to do is just call the stats program from inside my own program. (BTW I can't just require it because its a C program)... I came up with the following code to put near the top of my scripts:

#!/usr/bin/perl use strict; { local $ENV{REQUEST_METHOD} = "GET"; local $ENV{QUERY_STRING} = "query_string_for_stats_prog"; system("stats.cgi"); }

Well here's my question, when I run this from the command-line (used a test script that printed out the %ENV hash) I get the expected results. But when I run it from the web I don't get anything, as though the system command completely fails.

Does anyone have an idea how I could solve this? It doesn't have to use system, anything would help right now! :)

Thanks in advance

Lobster Aliens Are attacking the world!

Replies are listed 'Best First'.
Re: Do programs called with system() seen the current %ENV?
by diotalevi (Canon) on Mar 17, 2003 at 23:27 UTC

    The command probably failed. Double check which directory your server uses as the current working directory (probably /) and double check the path you're calling stats.cgi with. You probably just have to supply the path to the program.

Re: Do programs called with system() see the current %ENV?
by Steve_p (Priest) on Mar 18, 2003 at 02:41 UTC

    The typical UNIX daemon, when running, do a chdir to "/". So when Perl sees "stats.cgi", it sees "/stats.cgi". To take care of this, try putting a path in front filename.

    As far as dealing with your sysadmin, cut him out of the loop by running your log analyzer off of your server. :-)

Re: Do programs called with system() see the current %ENV?
by cfreak (Chaplain) on Mar 18, 2003 at 14:40 UTC

    Thanks to those of you who replied, I had a brain-dead moment, the answer of course is obvious.

    The perl tests I was using now work, unfortunatly it seems that the C program does something funky to get the QUERY_STRING as it still doesn't seem to work. I think I'm going to have to come up with plan 2.

    Lobster Aliens Are attacking the world!