putenv
Christophe
chris.cavalaria at free.fr
Tue Dec 20 12:39:04 EST 2005
Mike Meyer a écrit :
> Terry Hancock <hancock at anansispaceworks.com> writes:
>
>>On Tue, 20 Dec 2005 05:35:48 -0000
>>Grant Edwards <grante at visi.com> wrote:
>>
>>>On 2005-12-20, dpugmire at gmail.com <dpugmire at gmail.com>
>>>wrote:
>>>
>>>>I have csh script that calls a bunch of python programs
>>>>and I'd like to use env variables as kind of a global
>>>>variable that I can pass around to the pythong scripts.
>>>
>>>You can't change the environment of the parent process.
>>>
>>>IOW, the python programs can't change the environment of
>>>the calling csh script (or, by extenstion, the environment
>>>of subsequent python programs that are called by the csh
>>>script).
>>
>>There is an evil trick, however:
>>
>>Instead of setting the environment directly, have the python
>>program return csh code to alter the environment the way you
>>want, then call the python code by "sourcing" its output:
>>
>>source `my_script.py`
>
>
> Does this actually work? It looks to me like you need two levels:
> my_script.py creates a file, then outputs the name of the file, as the
> csh source command reads commands from the file named as an argument.
Should work, even in basic sh. IIRC, source means the shell should
execute the data itself. I've always used it with an intermediate file
but I wouldn't be surprised if there was a way to make it work with a
command output.
More information about the Python-list
mailing list