49 lines
1.7 KiB
Plaintext
49 lines
1.7 KiB
Plaintext
From: duncan at rcp.co.uk (Duncan Booth)
|
|
Date: 29 Apr 1999 09:11:18 GMT
|
|
Subject: 'sourcing' Python scripts?
|
|
References: <372713AD.6ABA444@cern.ch>
|
|
Message-ID: <8DB767BD4duncanrcpcouk@news.rmplc.co.uk>
|
|
Content-Length: 1501
|
|
X-UID: 720
|
|
|
|
Haimo G. Zobernig <Haimo.Zobernig at cern.ch> wrote in
|
|
<372713AD.6ABA444 at cern.ch>:
|
|
|
|
>Dear Python experts,
|
|
>
|
|
>this might be a unix rather than a Python problem, but I need to set
|
|
>environment variables from a Python program *in the parent process*
|
|
>that is running the Python script ( a la os.environ['BAR'] = 'foo' ).
|
|
>In other words, I want to achieve the equivalent of 'sourcing' the
|
|
>Python script. Can this be done? Even better would be a solution that
|
|
>also works on the various WinAbominations... (well, NT at least)
|
|
|
|
About the only way to make this work would be to make the python program
|
|
output a shell script that sets the environment variables and 'source' the
|
|
output. Something similar should work on NT/95 although you would have to
|
|
output appropriate syntax for the system in use.
|
|
|
|
For example, the following abomination works on Windows NT 4 SP4:
|
|
--------- something.bat or something.cmd --------------
|
|
@echo off
|
|
set XYZZY="------------------"
|
|
echo XYZZY is %XYZZY%
|
|
for /F "tokens=*" %%i in ('d:\progra~1\python\python.exe test.py') do %%i
|
|
echo XYZZY is %XYZZY%
|
|
-------------------------------------------------------
|
|
|
|
---------- test.py -------------------
|
|
print "SET XYZZY=Hello World"
|
|
--------------------------------------
|
|
|
|
|
|
--
|
|
Duncan Booth duncan at dales.rmplc.co.uk
|
|
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
|
|
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
|
|
http://dales.rmplc.co.uk/Duncan
|
|
|
|
|
|
|
|
|