0

I execute a perl script with exec via php, however I receive an error that the module Net::DNS is missing. I have installed the module as a regular user and as such is located in /home/user/perl5/i686-linux-thread-multi and I do use a full path (/usr/bin/perl) in the exec.

I've even tried to add the /home/user/perl5/i686-linux-thread-multi directory to @INC but the script still throws the error...

And I also tried to install the module with custom install path directly into /usr/lib/perl5/vendor_perl, but that didn't solve the problem either. And symlink didn't fix that either.

Here is the error message

  Can't locate Net/DNS.pm in @INC (@INC contains: 
/usr/lib/perl5/site_perl /usr/share/perl5/site_perl /usr/lib/perl5/vendor_perl 
/usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl

Any idea how this can be solved, sort of running out of ideas how to deal with this.

2 Answers 2

2

before exec, add:

$ENV{PERL5LIB} = "$ENV{PERL5LIB}:/home/user/perl5/i686-linux-thread-multi";

Why using use lib wont work (for pavel's comment):

#!/usr/bin/env perl
use strict;
use warnings;
use lib "hate_you";
use Data::Dumper;

print Dumper(\@INC);

print "In sub process....\n";
exec(qq{perl -MData::Dumper -e "print Dumper(\@INC);"});

will print on my machine:

$VAR1 = [
          'hate_you',
          '/etc/perl',
          '/usr/local/lib/perl/5.14.2',
          '/usr/local/share/perl/5.14.2',
          '/usr/lib/perl5',
          '/usr/share/perl5',
          '/usr/lib/perl/5.14',
          '/usr/share/perl/5.14',
          '/usr/local/lib/site_perl',
          '.'
        ];
In sub process....

    $VAR1 = '/etc/perl';
    $VAR2 = '/usr/local/lib/perl/5.14.2';
    $VAR3 = '/usr/local/share/perl/5.14.2';
    $VAR4 = '/usr/lib/perl5';
    $VAR5 = '/usr/share/perl5';
    $VAR6 = '/usr/lib/perl/5.14';
    $VAR7 = '/usr/share/perl/5.14';
    $VAR8 = '/usr/local/lib/site_perl';
    $VAR9 = '.';
Sign up to request clarification or add additional context in comments.

1 Comment

this refers to exec's from Perl, I believe there is a similar env in php
0

an alternative would be to include your personal library in your script, so it is independent from the environment set:

use lib qw(/home/user/perl5/i686-linux-thread-multi);

use Net::DNS;

2 Comments

I doubt this will work, use lib modifies the @INC in the current process not other spawned (like exec) from the current one.
why wouldn't it work when used in the Perl program you exec? Never had problems with that...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.