我正在尝试使用 Perl 脚本在我们拥有的工具(wpj)中添加某些目录。直接命令看起来像

 $ 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";

为此我得到
wpj: not found

但是,来自 shell 的相同调用会成功。有些东西没有正确导出,你能给我一些关于如何将调用环境导出到由反引号创建的子shell的建议吗?

最佳答案

检查 PATH 并根据需要修改其内容:

use Env qw(@PATH);

# check the PATH:
print join("\n", @PATH);

# modify its content:
push @PATH, "/usr/bin/wpj";

此模块的 The official manual

关于perl - 如何将调用环境正确导出到 Perl 的子 shell 中?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11542495/

10-10 05:01