Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by jwkrahn (Abbot)
on Oct 02, 2020 at 06:11 UTC ( [id://11122469]=note: print w/replies, xml ) Need Help??


in reply to Perl script runs fine if exec'd from the directory, but gives error if run outside the directory.

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.

There is no variable $text in the code you posted.

$array_creds = Config::Tiny->read('vnxe_config.conf');

This file is not available outside the directory.

  • Comment on Re: 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^2: 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 07:37 UTC

    "There is no variable $text in the code you posted."

    The error is from Win32::ShellQuote, line 85.

Re^2: 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 06:56 UTC

    Hi,

    Yes you are right. I'm using that file to read the username and password which unfortunately I cannot provide here. 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.

    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.

      "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.

        Hi Marto,

        Thank you for the fantastic clarification.

      $text is in the module code for Win32/ShellQuote.pm. However looking at that code isn't going to resolve the problem. The way to track this issue down is to perform a binary search. Get rid of half the code. If the bug goes away it was in the half of the code you removed. If the bug remains it is in the half you retained. Halve the chunk of code manifesting the bug then rinse and repeat.

      By definition the bug is something to do with your context when you run the script. We don't have your context so we can't debug for you. Either strip your example down to something we can run that exhibits the problem, or do the debugging yourself.

      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://11122469]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-24 22:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found