2
votes

I'm trying to run a perl script that is located in a remote linux server from windows using the python program. I'm using the subprocess.call method.

This is the python line of code

returnCd = subprocess.call(['plink', '-ssh', \
    '%s@%s' %('******','*****.***.com'), '-pw', '****', \
    'perl', '/apps/CACSGDEV/springbatch/perlscript/DEBTOR_VERIFICATION.pl'], \
    shell=True)

And this is what i see in the console (broken over lines for readability)

Can't locate ENVRC.pl in @INC (@INC contains: /usr/local/lib64/perl5 
    /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl 
    /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) 
at /apps/CACSGDEV/springbatch/perlscript/DEBTOR_VERIFICATION.pl line 16.

The file DEBTOR_VERIFICATION.pl has the following @ line 16

require "ENVRC.pl";

The file ENVRC.pl is in the same path as that of the DEBTOR_VERIFICATION.pl. Can anyone please suggest?

1
The directory in which the DEBTOR... resides is itself not in @INC, so ENVRC.pl is indeed not found in @INC ((unless there is a link to that /apps/... in some directory in @INC?) How is DEBTOR... program started? - zdim
Usually we run this 'DEBTOR_VERIFICATION.pl' program by connecting through putty. It runs fine without any issues. lincacsgqld.ams.com:/apps/CACSGDEV/springbatch/perlscript> DEBTOR_VERIFICATION.pl Executing program DebtorVerification return_code == 0 All transactions are processed without any validation errors Job Finished - mo-ta-to
Ah. When you run the program directly there is no need for @INC. When a file is to be loaded that's when @INC is searched for it. So, the directory of ENVRC.pl is not in @INC and the program can't be found. The other one runs OK because it is directly executed, not needing @INC. - zdim

1 Answers

3
votes

The program DEBTOR_VERIFICATION.pl is directly executed and thus it doesn't need to have its directory in @INC. On the other hand, when a file need be loaded via require (or use, which uses require) then it is precisely the directories in @INC that are searched for it. Since /apps/.., where ENVRC.pl resides, is not there the file cannot be found.

You need to add that directory to @INC and a good way to do it is via lib pragma

use warnings;
use strict;
...
use lib "/apps/CACSGDEV/springbatch/perlscript";
...

But if this program (DEBTOR_VERIFICATION.pl) and the required file ENVRC.pl will always stay in the same directory it is better to use FindBin instead of hard coding the path

use warnings;
use strict;
...
use FindBin qw($RealBin);
use lib $RealBin;

In either case the files in that directory can now be found by use and require (and do).

The DEBTOR program works when executed right from its directory, in older Perls, since the . (the current working directory) used to be included in @INC by default. We see that this is the case from @INC printed in the error message. So . gets searched and ENVRC.pl is found.

Relying on that has really always been a bad practice, but as of perl v5.26.0 (perldelta) (May 2017) the . directory is not in @INC anymore.

So you should add the above use lib statement to the DEBTOR... program anyway.