Reputation: 89
First Module:
package Compute;
our $sort_script= "/app/scripts/python_script.py";
Second Module:
package ProcessRestart;
use Compute;
# This perl module is also in /app/scripts/
# host1.com is an argument or script parameter
$returnMsg= `$Compute::sort_script host1.com`;
Above is an example of a perl module I have written. It calls the python script from other modules and pass it in the necessary arguments/parameters.
I have tried removing typing the actual path of the script and replacing it with "./python_script.py" but it does not seem to work.
I have tried printing the directory upon running the script using Cwd, it points to my home directory.
What other ways can I try to have a relative path to the script?
Upvotes: 1
Views: 184
Reputation: 385496
I think you're asking how to execute a script that's located in the same dir as the module that executes it.
use Path::Class qw( file );
my $qfn = file(__FILE__)->dir->file('python_script.py');
or
use File::Basename qw( dirname );
my $qfn = dirname(__FILE__) . '/python_script.py';
or
use Dir::Self qw( __DIR__ );
my $qfn = __DIR__ . '/python_script.py';
__FILE__
is a special token that returns the path to the file in which the symbol is located.
Upvotes: 3