Mike Meyer mwm at mired.org
Tue Dec 20 09:59:58 EST 2005

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.

To be able to output the commands directly, you'd need to use the eval
command, not the source command.

> It's ugly, but it does work -- I have had to use this
> before in a production environment.  Well, it's not really
> any less advisable than scripting in csh to begin with. ;-)

Doesn't matter what you're scripting in - you'll have to do some such
circumlocution to set the parent scripts environment variables.

Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

More information about the Python-list mailing list