[Python-au] Environment vars
Mike Dewhirst
miked at dewhirst.com.au
Thu Aug 18 05:21:43 CEST 2005
Grant McDonald wrote:
> Mike,
>
> If that's all you're trying to do then use an os.exec*e or os.spawn*e
> functions and pass in a modified environment mapping.
Thank you Grant : )
I now understand more than I did. I have two questions ...
> example:
>
> import os
> myenv = {}
> myenv.update(os.environ)
1. is there anything wrong with
myenv = os.environ
> myenv['ISC_USER'] = "joe_bloe"
> myenv['ISC_PASSWORD'] = "password"
>
> args = ["create_db.exe", "create_my_db.sql"]
2. what is the lower case r doing in the parameters?
> os.spawnve( os.P_WAIT, r"c:\mydbengine\create_db.exe", args, myenv)
>
> That should solve your problem.
It certainly solved some of it. The more I do the more probs I uncover.
C'est la vie huh?
Thanks
Mike
>
> Regards,
>
> Grant
>
> -----Original Message-----
> From: Mike Dewhirst [mailto:miked at dewhirst.com.au]
> Sent: 18 August 2005 10:25
> To: Grant McDonald
> Subject: Re: [Python-au] Environment vars
>
>
> Grant McDonald wrote:
>
>>Can i ask what your trying to modify it for?
>
>
> I want to call Firebird's isql utility to create a database. I can pass
> the name of the script in the command line but not the userid and
> password of the database owner. For that, isql looks at two environment
> vars: ISC_USER and ISC_PASSWORD
>
> If I'm calling isql from either a bash or batch script I can easily set
> those vars - but I want a single source python script to get away from
> maintaining both a bash and a batch script.
>
> Mike
>
>
>>-----Original Message-----
>>From: Mike Dewhirst [mailto:miked at dewhirst.com.au]
>>Sent: 18 August 2005 09:47
>>To: Grant McDonald
>>Cc: python-au at python.net
>>Subject: Re: [Python-au] Environment vars
>>
>>
>>Grant McDonald wrote:
>>
>>
>>>Not entirely sure,
>>>
>>>The docs say you should modify os.environ directly since it automatically
>>>calls putenv, but as you stated on WinXP and as you say it doesn't seem to
>>>work. I guess putenv may not be supported on WinXP.
>>>
>>>If you want a reliable way of modifying the environment on WinXP use the
>>>registry (unfortunately platform specific):
>>
>>
>>I'd prefer to stay platform neutral. I think I'll detect os.name and
>>scribble out a batch file to set a couple of vars if it is 'nt'.
>>
>>Thanks
>>
>>Mike
>>
>>
>>
>>>System environment ->
>>>
>>>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
>>>Manager\Environment
>>>
>>>User environment ->
>>>
>>>HKEY_CURRENT_USER\Environment
>>>
>>>
>>>Regards,
>>>
>>>Grant McDonald
>>>
>>>
>>>
>>>-----Original Message-----
>>>From: python-au-bounces at python.net [mailto:python-au-bounces at python.net]On
>>>Behalf Of Mike Dewhirst
>>>Sent: 17 August 2005 21:28
>>>To: python-au at python.net
>>>Subject: [Python-au] Environment vars
>>>
>>>
>>>I'm having difficulty inserting a couple of vars into the environment from
>>>within a script.
>>>
>>>os.putenv(varname, value) doesn't seem do it.
>>>
>>>The code doesn't barf but (in Windows XP) the set command doesn't indicate
>>>it actually happened. I haven't tried it with Linux.
>>>
>>>Is there a trick to it?
>>>
>>>TIA
>>>
>>>Mike
>>>
>>>
>>>
>>
>>
>
More information about the python-au
mailing list