perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "B Wooster" <>
Subject [mp2] [question] How to change $ENV{PATH} for a specific script?
Date Wed, 16 Jan 2008 22:16:10 GMT
I have searched through all the web docs and Usenet, but not found
anything that suggests anything special has to be done in mod_perl
scripts that need to set $ENV{PATH}

My specific example is that I need to add /usr/local/bin to PATH, but
I''ve been unable to find a way to do this, looks like mod_perl
scripts execute the line that changes $ENV{PATH}, but when a qx()
back-tick command is executed, that command is executed under the
value of the original path.

In case it helps, here's a simple test on Fedora FC7 system (more
version info at end):
#!/usr/bin/perl -Tw
print "Content-type: text/plain\n\n";

my $command = "basename";
foreach ( "/bin:", "/invalid/dir:" ) {
    $ENV{PATH} = $_;
    print "------ Testing command '$command', path $ENV{PATH}\n";
    my $string = `$command testing` || '';
    print "    failed to execute '$command', \$? is $?/" . ($? >> 8) . " : $!\n"
        if ($? != 0);
    print "    output \$string is: $string\n";

When run from the command line, I get the correct output:
Content-type: text/plain

------ Testing command 'basename', path /bin:
    output $string is: testing

------ Testing command 'basename', path /invalid/dir:
[Wed Jan 16 17:13:39 2008] Can't exec "basename": No such
file or directory at /home/cgi/ line 12.
    failed to execute 'basename', $? is -1/16777215 : No such file or directory
    output $string is:
But when I run this under Apache and mod_perl, I get this output -
/bin is still in the PATH even after removal:
------ Testing command 'basename', path /bin:
    output $string is: testing

------ Testing command 'basename', path /invalid/dir:
    output $string is: testing

/perl-status output snippet:
Embedded Perl version v5.8.8 for Apache/2.2.6
Under the "perl-script" handler, the environment is:
    MOD_PERL = mod_perl/2.0.3
    PATH = /sbin:/usr/sbin:/bin:/usr/bin

Any help appreciated!

View raw message