当前位置:首页> 正文

关于python:设置Mercurial Hook的环境变量

关于python:设置Mercurial Hook的环境变量

Setting Environment Variables for Mercurial Hook

我正在尝试调用一个shell脚本,该脚本通过Mercurial钩子在我们的服务器上设置了一堆环境变量。 当有新的变更组进入时,shell脚本会正常运行,但是环境变量不会继续调用shell脚本。

我在存储库中的hgrc文件如下所示:

1
2
3
[hooks]
changegroup = shell_script
changegroup.env = env

我可以看到shell脚本的输出,然后是env命令的输出,但是env命令不包括shell脚本设置的新环境变量。

我已经验证了shell脚本在单独运行时可以正常运行,但是在汞挂钩环境中运行时,它不能正确设置环境。


Shell脚本无法修改其环境。

http://tldp.org/LDP/abs/html/gotchas.html

A script may not export variables back to its parent process, the shell, or to the environment. Just as we learned in biology, a child process can inherit from a parent, but not vice versa

1
2
3
4
5
6
7
$ cat > eg.sh
export FOO="bar";
^D
$ bash eg.sh
$ echo $FOO;

$

而且,问题更大,因为您多次调用bash

1
2
bash 1 -> hg -> bash 2 ( shell script )
             -> bash 3 ( env call )

这就像在想我可以在一个php脚本中设置一个变量,然后简单地通过一个接一个地运行另一个对象来神奇地将其获取。


展开全文阅读

相关内容