Setting UNIX environment with a Python script
Cameron Hutchison
camh at zip.com.au
Mon Mar 11 19:14:20 EST 2002
On Tue, 12 Mar 2002 08:13:05 +1100, Grant Edwards wrote:
> In article <3C8D143A.17963385 at all.com>, Nom de Plume wrote:
>
>> The only step left is sourcing the ora_env.[name] file from within
>> Python in a way such that the environment of the parent shell is
>> modified. Anyone have any ideas? I have tried:
>
> It is not possible under Unix to modify the environment of your parent
> process. You can only modify your own environment and then export that
> environment to your children.
What you need to do instead is have your python program print on stdout
the name of the ora_env file to source. Then you invoke your python
script from your shell login script like this (bourne style shell
assumed):
eval "source ora_env.`get_ora_name`"
where get_ora_name is your python script.
If you're not familiar with shell scripting, look up command substitution
or backquote substitution in the manpage for how this works.
[To be honest, I can't remember if 'source' is bourne shell or a
bash-ism. You can always use the . command, but that doesn't look
as clear and may have been harder to explain]
More information about the Python-list
mailing list