Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^3: Perl script runs fine if exec'd from the directory, but gives error if run outside the directory.

by marto (Cardinal)
on Oct 02, 2020 at 08:27 UTC ( [id://11122473]=note: print w/replies, xml ) Need Help??


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.

  • Comment on Re^3: Perl script runs fine if exec'd from the directory, but gives error if run outside the directory.
  • Select or Download Code

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

    Hi Marto,

    Thank you for the fantastic clarification.

      No problem, let me know if you have any further questions about this. As Grandfather mentioned earlier, it's often much simpler to provide a short example which reproduces the problem, rather than post the entire script.

        In this case, as is often the case, the problem would have been found in the process of whittling down the code. That is often by far the best outcome in my view.

        Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11122473]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-26 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found