in reply to Re^2: Perl script runs fine if exec'd from the directory, but gives error if run outside the directory.
in thread Perl script runs fine if exec'd from the directory, but gives error if run outside the directory.
"Also there's no $text variable in my script nor am I doing any substitution. Even if I embed the username and password in the script I still get the error."
The error tells you exactly where this is coming from:
G:\>perl cdr_vnxe\cedar_rapids_vnxe_v2.pl Use of uninitialized value $text in substitution (s///) at G:/Strawber +ry/perl/vendor/lib/Win32/ShellQuote.pm line 85.
"What baffles me is the script works fine if I run it from the directory where its in. No errors whatsoever. Just when I run it with the path, the error comes up. "
You have:
my $array_creds = Config::Tiny->new(); $array_creds = Config::Tiny->read('vnxe_config.conf');
Consider the following example:
#!/usr/bin/perl use strict; use warnings; use Config::Tiny; my $Config = Config::Tiny->new; $Config = Config::Tiny->read( 'file.conf' ); print "$Config->{_}{var1}\n";
When run from the directory containing your config file:
marto@Marto-Desktop:~/code$ ./cf.pl derp
When run from the parent directory:
marto@Marto-Desktop:~$ ./code/cf.pl Use of uninitialized value in concatenation (.) or string at ./code/cf +.pl line 8.
As you see, the code can't find the config file.
#!/usr/bin/perl use strict; use warnings; use File::Basename; my $dirname = dirname(__FILE__); use Config::Tiny; my $Config = Config::Tiny->new; $Config = Config::Tiny->read( "$dirname/file.conf" ); print "$Config->{_}{var1}\n";
Runs fine:
marto@Marto-Desktop:~$ ./code/cf.pl derp
Update: IPC::Run3 needs Win32::ShellQuote because you are on Windows. https://metacpan.org/source/RJBS/IPC-Run3-0.048/Makefile.PL#L13.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Perl script runs fine if exec'd from the directory, but gives error if run outside the directory.
by pritesh_ugrankar (Monk) on Oct 02, 2020 at 19:30 UTC | |
by marto (Cardinal) on Oct 03, 2020 at 09:42 UTC | |
by GrandFather (Saint) on Oct 04, 2020 at 03:05 UTC |