I am trying to use a Perl script to add certain directories in a tool(wpj) we have. The direct command would look something like
$ wpj add path/to/desired/library makefile.wpj
I want to do a script to automate this since a lot of this has to be done. However, a very special set of environment variables among other things are setup to make 'wpj'. If I call wpj with backquotes from Perl, the call fails. You can see the code below
$command = "wpj add library path\\to\\file.wpj \\path\\to\\add";
print $command."\n";
$result = `$command`;
print "->".$result."\n";
For this I get
wpj: not found
However, the same call from the shell succeeds. Something is not correctly exported, could you please give me suggestions on how to export the calling environment into the subshell created by backquotes?
Check the PATH and modify its content if needed:
use Env qw(@PATH);
# check the PATH:
print join("\n", @PATH);
# modify its content:
push @PATH, "/usr/bin/wpj";
The official manual for this module.
The environment is inherited without you have to do anything. I suspect wpj
is not an executable, but a shell alias. As such, you'll need to run the command in a shell that has that alias defined. This might require an interactive shell, depending on how you create your aliases.
system('bash', '-i', '-c', 'wpj add path/to/desired/library makefile.wpj');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With